【发布时间】:2019-01-30 21:00:26
【问题描述】:
我正在使用 react native 来构建 iOS 应用。通过使用react-native-image-picker,我设法在我的手机模拟器上获得了图像的uri。我不知道如何将其上传到 Amazon S3(使用 aws Amplify 中的“存储”)。
ImagePicker.launchImageLibrary(options, (response) => {
console.log('Response = ', response);
this.setState({
imFileName: response.fileName,
fileData: response.data,
fileURL: response.uri
});
this.putFileInS3();
}
putFileInS3 = async () =>
{
Storage.put(this.imFileName, new Buffer(this.fileData, 'base64'), { contentType: 'image/jpeg'})
.then(() => {
console.log('successfully saved image to bucket')
})
.catch(err => {
console.log('error saving file to bucket')
})
}
我得到错误:
Possible Unhandled Promise Rejection (id: 0):
TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
如何正确调用 Storage.put()?
【问题讨论】:
标签: reactjs amazon-web-services react-native amazon-s3 aws-amplify