我创建了一个应用程序,该应用程序捕获图像并上传到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);
我工作正常。但是,现在我需要从其他文件夹上传它们,所以我面临此问题。
有人可以帮助我解决这个问题吗?
尝试使用"类型:image/jpg"或&quot type:image/png;而不是" content-type"
i正在遇到此错误,因为文件type
未定义。实际上,文件类型不应为 undefined/null
。我认为将ContentType传递到配置并不重要。