Last active
May 25, 2021 14:38
-
-
Save EQuimper/90fba31f9d0ecb8f6926709a4dbc46d2 to your computer and use it in GitHub Desktop.
Upload a image using presign url from s3 in React-Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function uploadImage(method: string, url: string, file: any) { | |
return new Promise((resolve, reject) => { | |
const xhr = new XMLHttpRequest() | |
xhr.open(method, url) | |
xhr.setRequestHeader('Content-Type', file.type) | |
xhr.onload = () => { | |
if (xhr.status !== 200) { | |
reject( | |
new Error( | |
`Request failed. Status: ${xhr.status}. Content: ${xhr.responseText}` | |
) | |
) | |
} | |
resolve(xhr.responseText) | |
} | |
xhr.send(file) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm doing it like this :
But I'm keep getting this error
seems to be related to local size and actual upload size of the file which is modified, god know why, RN bug... Do you have any ideas about how to fixe it ?