我想将照片上传到 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)));
获得图像后,我通过以下方式将图像上传到 s3 存储桶{ Storage } from 'aws-amplify'
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 存储桶中将文件标记为公开。