我正在使用react-native-image-picker
在我的 iOS 模拟器手机上为我的 react 本机应用程序获取视频的文件路径。如何使用它通过 Amplify 上传到 S3?
import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';
import {Storage} from 'aws-amplify';
class App extends Component {
constructor(props) {
super(props)
}
//This function is called on a Button click
pickVideo = async () => {
const options = {
mediaType: 'video'
};
ImagePicker.launchImageLibrary(options, (response) => {
if(response.didCancel){
console.log('User cancelled image picker');
}
else if (response.error){
console.log('ImagePicker error: ', response.error);
}
else{
this.setState({
vidFileName: response.fileName,
});
console.log(response.uri);
this.putFileInS3(response.path, repsonse.filename);
}
});
}
readFile = (somefilePath) => {
return RNFetchBlob.fs.readFile(somefilePath, 'base64').then(data => new
Buffer(data, 'base64'));
}
putFileInS3 = (filePath, fileName) => {
this.readFile(filePath).then(buffer => {
Storage.put(fileName, buffer, { contentType: 'video/mp4' })
.then(() => {console.log('successfully saved to bucket');})
.catch(e => { console.log(e);});
}
}
尽管我从图像选择器那里得到了响应,但在尝试上传时显示 AWSS3Provider:参数中缺少必需的键"存储桶",即使用户以 IAM 用户身份登录,使用 with Authenticator。
您需要配置存储桶。https://aws-amplify.github.io/docs/js/storage
上面链接中的一些示例:1 -
Storage.configure({
AWSS3: {
bucket: '',//Your bucket ARN;
region: ''//Specify the region your bucket was created in;
}
});
阿拉伯数字-
import Amplify from 'aws-amplify';
Amplify.configure({
Auth: {
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region
userPoolId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito User Pool ID
userPoolWebClientId: 'XX-XXXX-X_abcd1234',
},
Storage: {
AWSS3: {
bucket: '', //REQUIRED - Amazon S3 bucket
region: 'XX-XXXX-X', //OPTIONAL - Amazon service region
}
}
});