0

I'm having trouble while reading data from POST request.

Request screenshot

It seems everything is fine from frontend but when I'm getting nothing when trying to read the request data on the backend.

request.FILES
<MultiValueDict: {}>

request.POST
<QueryDict: {}>

request.body
*** RawPostDataException: You cannot access body after reading from request's data stream

Backend view code

def upload_file(request):   
  upload_response = requests.post(requestbuilder.create_request('/files'), files={request.FILES['file']._name:request.FILES['file']}, headers=requestbuilder.MULTIPART_HEADERS)
  return HttpResponse(upload_response.json().get('fileUrl'))

Options for ajax call

var options = {
    url: "/apps/upload/",
    method: 'post',
    addRemoveLinks: true,
    clickable: false,
    maxFiles: config.maxFiles,
    minWidth: config.minWidth,
    minHeight: config.minHeight,
    headers: {
        'X-CSRFToken': $("input[name=csrfmiddlewaretoken]").val()
    },
   }

I'm completely blank, any help would be appreciated.

8
  • can you post all the backend process please ? Sep 26, 2017 at 13:56
  • Currently, I'm just trying to read the data from request's object but I'm stuck on the same. Sep 26, 2017 at 13:58
  • You're using django rest framework ? can you show the serializers or the form definition? Sep 26, 2017 at 14:00
  • @Bestasttung I'm not using any serializer. even not added rest-framework in the app. Sep 26, 2017 at 14:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.