Example #1
0
def handle_uploaded_photo(f):
    if f.name == '':
        raise NotImplemented
    photo = Photo(author="simon", description="what so ever")
    photo.file.new_file()
    
    for chunk in f.chunks():
        photo.file.write(chunk)
        #destination.write(chunk)
    #destination.close()
    photo.file.close()
    photo.file.content_type="image/jpeg"
    photo.save()
Example #2
0
def store_photo_to_db(file, author, description, content_type):
    ''' Store uploaded photo into GridFS (mongoDB) '''
    if file.name == '':
        raise ValueError
    r = Restraunt.objects().first()
    photo = Photo(author=author, description=description)
    photo.file.new_file()
    
    for chunk in file.chunks():
        photo.file.write(chunk)
    photo.file.content_type=content_type
    photo.file.close()
    photo.save()
    r.photos.append(photo)
    r.save()
    return photo