我创建了一个简单的应用程序,该应用程序捕获了图像并将其上传到AWSs3。我想将这些图像存储在我的应用程序文件夹中。 (安装我的应用程序后,便创建了该文件)。我想将捕获的图像存储到该文件夹而不是“图片”文件夹。我正在使用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在外部提及目标目录。但是我没有。
有人可以帮助我吗?
答案 0 :(得分:0)
假设文件夹已经存在图库文件夹
尝试一下:
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}`));