-
-
Save jason-shen/ff116838bd8b0e60f502d8224ae95563 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