我创建了一个简单的应用程序,它捕获图像并上传到AWSs3。我想将这些图像存储在我的app文件夹中。 (我已经安装了我的应用程序后创建了这个)。我想将捕获的图像存储到该文件夹而不是图片文件夹。我正在使用react-native-image-picker来捕获图像。
我的代码是,
import ImagePicker from 'react-native-image-picker';
import RNFS from 'react-native-fs';
takePic = () => {
const options = {
quality: 1.0,
maxWidth: 100,
maxHeight: 100,
base64: true,
skipProcessing: true
}
const pictureFolder = RNFetchBlob.fs.dirs.SDCardDir+'/Pictures/Text/';
ImagePicker.launchCamera(options,(responce)=>{
this.state.testImage.push({ uri: responce.uri });
const file ={
uri : responce.uri,
name :DeviceInfo.getUniqueID()+'_'+this.props.longitude+'_'+this.props.latitude+'_'+this.state.capturedTime+'_'+this.state.schoolId+'_'+this.state.userId+'_'+this.state.SelectedClass+'_'+this.state.SelectedSection+'_'+this.state.SelectedSubject+'.jpg',
method: 'POST',
//path : pictureFolder+responce.fileName,
path : responce.path,
type : responce.type,
notification: {
enabled: true
}
}
console.log(pictureFolder);
});
(我只更新了部分代码)。我尝试使用react-native-fs在外部提到目标目录。但是我没有。
任何人都可以协助我这样做吗?
假设文件夹已经有了库文件夹
const APP_FOLDER_NAME = 'MyApp';
const pictureFolder = `${RNFS.PicturesDirectoryPath}/${APP_FOLDER_NAME}`;
ImagePicker.launchCamera(options, (response) => {
const { uri } = response;
const fileName = new Date().getTime();
RNFS.copyFile(uri, `${pictureFolder}/${fileName}`)
.then(() => RNFS.scanFile(`${albumPath}/${fileName}`));
});
此步骤对于在不重新启动模拟器或设备的情况下查看文件夹中的文件非常重要:
.then(() => RNFS.scanFile(`${albumPath}/${fileName}`));