reactjs - 如何使用 Amplify 或 RNFetchBlob 将视频上传到 S3?
问题描述
我正在使用react-native-image-picker
在我的 iOS 模拟器手机上为我的 react 本机应用程序获取视频的文件路径。我如何使用它通过 Amplify 上传到 S3?
import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';
class App extends Component {
constructor(props) {
super(props)
this.state = {
vidFileName: '',
fileURI: '',
}
this.putFileInS3 = this.putFileInS3.bind(this);
}
pickVideo = async () => {
const options = {
mediaType: 'video'
};
ImagePicker.launchImageLibrary(options, (response) => {
console.log('Response = ', response);
this.setState({
vidFileName: response.fileName,
fileURI: response.uri,
});
this.putFileInS3();
}
}
readFile = (somefilePath) => {
return RNFetchBlob.fs.readFile(somefilePath, 'base64').then(data => new
Buffer(data, 'base64'));
}
putFileInS3 = async () =>
{
RNFetchBlob.fs.readFile(this.fileURI).then(buffer => {
Storage.put(vidFileName, buffer, { contentType: 'video/mp4' })
conole.log('successfully uploaded video to bucket');
}).catch(e => {
console.log(e);
});
}
我正在尝试遵循:https://aws-amplify.github.io/docs/js/storage,在 React Native 应用程序中上传图像部分。但也许我错过了什么?你能帮忙吗?
Error: file:///Users/xxxxxxxxxx/Library/Developer/CoreSimulator/Devices/xxxxxxxxx/data/Containers/Data/Application/5CxxxxxxxxxxxxxC79/tmp/4xxxxxxxxxxxxxx.MOV . <-URI
App.js:130 Error: file not exists
at createErrorFromErrorData (NativeModules.js:146)
at NativeModules.js:95
at MessageQueue.__invokeCallback (MessageQueue.js:397)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:72
解决方案
这个包非常适合将数据发送到 S3 中的存储桶react-native-aws3。
如果您在使用该软件包时需要任何帮助,请发表评论。
推荐阅读
- javascript - serviceworker.js:1 Uncaught (in promise) TypeError: Request failed .Net Core 3.1
- c++ - 如何在多个函数中插入链表节点而不使用 C++ 中的全局变量?
- mysql - SQL 不显示重复项/仅显示最后一个值
- google-cloud-platform - 获取 openApi 规范中定义的自定义属性
- php - Symfony 5 - DateType::class 的约束
- javascript - 在 ReactJS 中做了一个
- string - 如何从我的日志文件中解析时间戳?
- docker - 如何从 Docker Hub 中删除存储库
- html - jQuery diable 多选下拉选项
- pine-script - 如何将两个函数从 MQL4 转换为 pine 脚本