I am changing my form submission to make it more fluid via using fetch.
In order to process the value of my input image:
<input name="perfil" type='file' id="imageUpload />
And then, in order to upload it to Amazon S3,
I do this in my views.py:
if request.method == "POST" image = request.FILES['perfil'] im = Image.open(image) output = BytesIO() rgb_im = im.convert('RGB') rgb_im.save(output, format='JPEG', quality=90) output.seek(0) s3.Bucket('bucketname').upload_fileobj(output, request.user.email + '.profileImage') But now (because i'm trying to implement fetch), I am getting the image file like this:
fetch(`url`, { method: 'POST', body: JSON.stringify({ image: document.querySelector('#imageUpload').files[0], }), headers: { "Content-type": "application/json; charset=UTF-8", "X-CSRFToken": getCookie('csrftoken') } }) } The problem is that when I do request.body['image`] in the server (views.py), all I'm getting is this: "image":{}
And I don't know how to process this file in JS before I send it to the server (that will end up uploading it to amazon s3)