Question:
Friends, Countrymen, Lend me your ears…
I’m signing my url for amazon s3, and then using fileReader and Fetch to put my file in s3.
Though when I do I get a fun white square instead of my image:
https://s3.amazonaws.com/hubbble/Gabe/lX4H0.png
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
const reader = new FileReader(); reader.onload = ((e) => { let s3headers = new Headers(); s3headers.append("content-type", 'image/png'); fetch(signedRequest, { method: 'PUT', headers: s3headers, body: e.currentTarget.result }).then((response)=>{ console.log(response); }); }); |
- Permissions Issue? Don’t really think so as you can definitely view the image
- Corrupted somehow?
- Maybe an incorrect content type?
Thoughts?
Thanks for any guidance, been banging my head against the wall on this!
Answer:
The contents of that appear to be a base64 encoded image. That is, you’re uploading a text file and not a binary image (and then saying it is, a image/png
) You could just convert it first doing something like this first.