How do I send file upload progress % in Django?

155 views Asked by At

I have a iOS app which can upload files to my Django API.

Heres the front-end code:

        AF.upload(multipartFormData: { multipartFormData in
            multipartFormData.append( data1!, withName: "one", fileName: "one")
            
        }, to: "https://httpbin.org/post")
        .response { response in
            print(response)
        }
        .uploadProgress { prog in
            print(prog.fractionCompleted)
        }

This works perfectly on https://httpbin.org/post , It keeps printing the progress % until its 100%.

However, When I post the same file my own API It will only print the progress once at 100%. So, I assume it's because I have to set up my http response so it also sends the progress %? How can i mimic the http response of httpbin.org/post ?

Heres what I have currently.

@csrf_exempt
def test (request):

    f = request.FILES["1"]
    default_storage.save(f.name, f)
    return HttpResponse("file saved")
1

There are 1 answers

0
Sam KC On

I feel stupid, wasted my whole day trying to figure this out, turns out it was because I was testing it in my localhost, therefore, the upload process is really fast and always returned 100%