我正在寻找一个完整的示例,说明如何在成功地将文件名发送到S3后返回文件名。
目前,我有这样的情况:
uploadImageAsync = async (pickerResult) => {
try {
this.setState({
uploading: true,
})
if (!pickerResult.cancelled) {
const response = await fetch(pickerResult.uri);
const blob = await response.blob();
Storage.put(fileName, blob)
.then(result => console.log(result))
.catch(err => console.log(err))
}
} finally {
this.setState({
uploading: false,
})
}
}我的返回结果是我创建的文件名。我想在创建S3文件名之后返回它。这个是可能的吗?
发布于 2018-10-01 18:21:08
您可以对图像执行一个get()调用以获得一个签名的url。
Storage.put('profile-picture.jpeg', blob)
.then(result => {
Storage.get('profile-picture.jpeg')
.then(result => {
console.log(result);
})
.catch(err => {
console.error(err);
});
})
.catch(err => {
console.error(err);
});发布于 2018-10-01 18:14:20
因此,您实际上不需要在执行put之后将S3文件的密钥返回给您,因为它总是有一个基于您为"put“提供的第三个参数的可预测键。
put函数自动为您配置文件名的前缀。但是,如果您出于任何原因需要"IdentityId“部分,您可以得到这样的部分:
Auth.currentCredentials().then(user => user.identityId)https://stackoverflow.com/questions/52569268
复制相似问题