[Fixed]-Need an Example of Django big File upload with upload file handler method

1👍

You’ll need to return the path of the created file (relative to the /media root) from your handle_uploaded_file function, and then save that to the model’s video field.

So something like:

def handle_uploaded_file(f):
    filename, extension = os.path.splitext(video.name)
    relative_path = "video/%s" % filename
    full_path = "media/%s" % relative_path
    with open(full_path, 'wb+') as destination:
    for chunk in f.chunks():
        destination.write(chunk)
    return relative_path

def form_valid(self, form):
    ...

    if video:
         relative_path = handle_uploaded_file(video)
         form.instance.video = relative_path
         form.instance.save()

Leave a comment