我将在 React Native 中将图像上传到 Amazon S3。
我有 S3 signedUrl 用于上传图片。
我如何在 React Native 中使用此 url 上传图片?
如果有人试过这个,请帮助我。
谢谢!
最佳答案
很简单,我花了很多时间才发现:
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// success
} else {
// failure
}
}
}
xhr.open('PUT', presignedUrl)
xhr.setRequestHeader('Content-Type', fileType)
xhr.send({ uri: filePath, type: fileType, name: fileName })
- filePath 是文件的完整路径
- fileType 是文件的 mime 类型
- fileName为文件名
来源:http://blog.rudikovac.com/react-native-upload-any-file-to-s3-with-a-presigned-url/
关于amazon-web-services - 如何在 React Native 中直接在 Amazon S3 上上传图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36670902/