Note that there are some explanatory texts on larger screens.

plurals
  1. POmultipart/formdata is not sending file data with jQuery.ajax
    primarykey
    data
    text
    <p>I have an endpoint from our Django backend guys with documentation that reads:</p> <blockquote> <p>POST to /api/1/photo-uploads/ with enctype="multipart/form-data" with files in field called "files[]".</p> </blockquote> <p>I've been attempting to send uploaded files with formData using jquery's AJAX method. I continue to get an error indicating that the file was not sent. When I view the payload I see.</p> <pre><code>undefined ------WebKitFormBoundary9AzM2HQPcyWLAgyR Content-Disposition: form-data; name="file"; filename="auzLyrW.jpg" Content-Type: image/jpeg </code></pre> <p>Which doesn't necessarily mean that it hasn't sent but there certainly isn't a location being posted. And I don't have any kind of verification that the file is uploaded.</p> <pre><code> var formData = new FormData(); formData.append('file', $('#file-upload').get(0).files[0]); $.ajax({ url: '/api/1/photo-uploads/', type: 'POST', data: formData, cache: false, contentType: false, processData: false, }); </code></pre> <p>When I console.log <code>formData</code> it simply show's the prototype methods like <code>.append</code>. So I'm unable to verify if the file's data is being sent beyond checking the payload. I can log <code>$('#file-upload').get(0).files[0]</code> but I only see details from the file itself. Because I'm testing it locally an upload location should be something like localhost:8000/.</p> <p>The backend guys are under the impression that it's something I'm doing. When I do a simple form post it works fine. I've tried a number of plugins and basic methods and all have produced the <code>400 {"message": "No photos supplied.", "success": false}</code></p> <p>Any ideas would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload