我创建了一个捕获图像并上传到 aws3 的应用程序。以前,拍摄的照片存储在图片文件夹中,我是从图片文件夹上传的。现在,我将所有照片存储在我的应用程序文件夹中(我在 android 设备中创建了一个文件夹)。因此,它给出了上述错误。我在 AWS 配置变量中将 contentType 称为“image/jpg”。但是,这个问题没有得到解决。
我的代码是,
import { RNS3 } from 'react-native-aws3';
import RNFS from 'react-native-fs';
import RNFetchBlob from 'react-native-fetch-blob';
takePic = () => {
const options = {
quality: 1.0,
maxWidth: 100,
maxHeight: 100,
base64: true,
skipProcessing: true
}
// create a path you want to write to,(folder is already there)
var pictureFolder = RNFetchBlob.fs.dirs.SDCardDir+'/School';
ImagePicker.launchCamera(options,(responce)=>{
this.state.testImage.push({ uri: responce.uri });
const file ={
uri : responce.uri,
name : responce.fileName,
method: 'POST',
path : responce.path,
type : responce.type,
notification: {
enabled: true
}
}
RNFetchBlob.fs.exists(pictureFolder).then((exists)=>{
if(exists){
RNFS.moveFile(responce.uri, `${pictureFolder}/${file.name}`)
.then(() => RNFS.scanFile(`${pictureFolder}/${file.name}`));
console.log("**************exists*******************");
}
})
this.setState(prevState => {
// get the previous state values for the arrays
let saveImages = prevState.saveImages;
// add the values to the arrays like before
saveImages.push(`${pictureFolder}/${file.name}`);
// return the new state
return {
saveImages
}
});
const base64 = RNFS.writeFile(responce.uri, responce.data);
return base64;
});
}
_upload=()=>{
if(this.state.connection_Status==="Online"){
const config ={
keyPrefix :aws_keyPrefix,
bucket : 'Testing/',
region :aws_region,
accessKey:aws_accessKey,
secretKey :aws_secretKey,
successActionStatus :201,
contentType:'image/jpg'
}
//store captured images in an array
this.state.saveImages.map((image) => {
RNS3.put(image,config)
.then((responce) => {
Alert.alert("Successfully, uploaded");
});
});
}
以前,我直接存储文件详细信息如下,
saveImages.push(file);
我工作得很好。但是,现在我需要从其他文件夹上传它们,所以我面临这个问题。
有人可以帮我解决这个问题吗?