Seq*_*ial 5 javascript blob amazon-web-services react-native aws-amplify
我有一张图片.我想使用aws-amplify将其上传到S3.所有Storage类上传示例都使用文本文档; 但是,我想上传一张图片.我正在使用expo,它没有来自react-native-fetch-blob的支持,并且本机反应没有blob支持......
所以我的选择似乎是:
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
const image = await ImagePicker.launchImageLibraryAsync({
quality: 0.5,
base64: true
});
const { base64 } = image;
Storage.put(`${username}-profileImage.jpeg`, base64);
}
它是否正确?
使用RN BLOB支持版本编辑更新的答案:我已经能够解决这个问题,因为React Native已经宣布了blob支持,现在我们只需要uri.请参阅以下示例:
uploadImage = async uri => {
const response = await fetch(uri);
const blob = await response.blob();
const fileName = 'profileImage.jpeg';
await Storage.put(fileName, blob, {
contentType: 'image/jpeg',
level: 'private'
}).then(data => console.log(data))
.catch(err => console.log(err))
}
Run Code Online (Sandbox Code Playgroud)
老答案
对于你所有你来说.我最终使用https://github.com/benjreinhart/react-native-aws3这完美无缺!但不是首选的解决方案,因为我想使用aws-amplify.
| 归档时间: |
|
| 查看次数: |
2711 次 |
| 最近记录: |