0

I'm trying to take an image with Swift, encode a base64 string, send it to a Django app, and recreate the image from that. However, all the images I've had have been unusable.

Here's my Swift code:

let imageData = UIImagePNGRepresentation(image)
let base64String = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
let postString = "image=" + base64String
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)

And here's my Python code:

base64_data = request.POST.get('image')
with open("melanie/images/%s.jpg" % image_name, "wb") as img:
        img.write(base64_data.decode('base64'))

Can anyone help me figure out where I'm going wrong?

0 Answers0