我有一个形象。我想使用 aws-amplify 将其上传到 S3。所有存储类上传示例均使用文本文档;但是,我想上传一张图片。我正在使用expo,它没有react-native-fetch-blob的支持,并且react native还没有blob支持......。
所以我的选择似乎是:
- 通过 lambda 创建节点服务。
- 仅将 base64 信息上传到 S3,而不是 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))
}
旧答案
对于你所得到的一切。我最终使用了https://github.com/benjreinhart/react-native-aws3 https://github.com/benjreinhart/react-native-aws3这很完美!但这不是首选解决方案,因为我想使用 aws-amplify。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)