1

I am uploading an image file:

oFReader.readAsDataURL(fileObject);

oFReader.onload = function(oFREvent){  
  var picture = oFReader.result; 
  (... continue)

And, ajaxing:

var dataDict = {'purpose':'newpicture', 'picture':picture};
$.ajax({
  type:'POST',
  url:'https://mydomain.whatever',
  data:JSON.stringify(dataDict)
})

When I print out 'picture' variable, it is like:

"data:image/jpeg;base64,/9j/4AAQSk...

Now, I am getting a new error on my AWS with Python 3.5, which did not occur on my local with Python 3.6. On line:

import json


if(request.body):
  data = json.loads(request.body)

I am getting the error:

TypeError: the JSON object must be str, not 'bytes'

I am guessing that it is because json.loads changed:

Changed in version 3.6: s can now be of type bytes or bytearray. The input encoding should be UTF-8, UTF-16 or UTF-32.

But, I thought that I was turning the image into base64 string. What am I sending? String or Bytes? How do I send this image as an string??

4
  • Try using request.get().json() instead of json.loads(request.body) Commented Jul 18, 2018 at 17:57
  • @Wamadahama Thanks for your response. I got error "AttributeError: 'WSGIRequest' object has no attribute 'get'" And this is Django project to be clear. Commented Jul 18, 2018 at 18:39
  • This might provide some insight on how to solve this: stackoverflow.com/questions/41006093/… Commented Jul 18, 2018 at 18:56
  • @Wamadahama OK! Take a look! Thanks again! :) Commented Jul 18, 2018 at 19:06

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.