【发布时间】:2018-11-28 00:42:21
【问题描述】:
我想将照片上传到 S3 存储桶,我目前使用 Expo 和 aws-amplify 来解决这个问题。
获取本地图片的代码如下:
import { ImagePicker } from 'expo';
ImagePicker.launchImageLibraryAsync({
mediaTypes: 'Images',
allowsEditing: true,
aspect: [1, 1],
base64: true
})
.then(image => dispatch(pickImageSuccess(image)))
.catch(err => dispatch(piclImageFail(err)));
获取图片后,我通过{ Storage } from 'aws-amplify'将图片上传到s3存储桶
import { Storage } from 'aws-amplify';
const file = image.base64;
const imageName = image.uri.replace(/^.*[\\\/]/, '');
console.log(imageName);
const access = { level: "public", contentType: 'image/jepg' };
Storage.put(`${username}/${imageName}`, file, access)
.then(succ => console.log(succ))
.catch(err => console.log(err));
之后 我上传了图片,我尝试在 S3 存储桶中打开图片。图像无法正常打开,也无法公开访问图像,除非我在 S3 存储桶中将文件标记为公开。
【问题讨论】:
-
可能是因为拼写错误:
contentType: 'image/jepg',应该是image/jpeg -
@Cherniv 谢谢,我注意到了,买还是不行。
标签: amazon-web-services react-native amazon-s3 expo aws-amplify