【发布时间】:2023-02-02 07:10:24
【问题描述】:
我希望在我的 Expo React Native 项目中添加将图像和视频上传到 S3 的功能。我正在使用 ImagePicker 来允许用户选择图像和视频……效果很好。我在使用签名 URL 上传视频时遇到问题 - 类型留空,因此无法播放 - 出于某种原因,它似乎对图像无关紧要。因此,我关注this tutorial 的 AWS Amplify,因为它似乎提供了一种将内容推送到 S3 存储桶的更强大的方式。 我根据文档配置了 Amplify - 它生成了一个 S3 存储桶。然后我按照文档中的描述设置身份验证并运行
amplify add storage
为我的项目添加存储 - 我包括了为我放大设置的存储桶。然后我将以下代码添加到我的 ImagePicker 函数中:
const imageName = result.assets[0].uri.replace(/^.*[\\\/]/, '');
const fileType = mime.lookup(result.assets[0].uri);
const access = { level: "public", contentType: {fileType} };
const imageData = await fetch(result.assets[0].uri)
const blobData = await imageData.blob()
console.log("Image name and filetype " + imageName + " and " + fileType);
try {
await Storage.put(imageName, blobData, access)
} catch (err) {
console.log('error: ', err)
}
结果是:
Image name and filetype E5E29BF9-6CD2-4D87-8B63-7FA9B0BE4A80.mov and video/quicktime
error: [TypeError: undefined is not an object (evaluating '_storage.default.put')]
我不确定如何继续对此进行故障排除以及为什么会出现该错误。任何帮助,将不胜感激
【问题讨论】:
标签: amazon-web-services react-native amazon-s3 expo