I am using this library react-s3 to upload images on S3 and delete from S3. Upload image is working fine but when I am trying to delete the file from s3 but whenever I try to delete I am getting 403. I am passing the following URL in delete function:
https://abc-profile-images.s3.amazonaws.com/1601273978.331.jpeg
But In catch block I received the following URL (why is it including url with and without region at the same time)
https://abc-profile-images.s3-ap-southeast-1.amazonaws.com/https://abc-profile-images.s3.amazonaws.com/1601273978.331.jpeg
Following is the object received in catch:
Response {type: "cors", url: "https://abc-profile-images.s3-ap-southeast-1.am…ages.s3.amazonaws.com/1601273978.331.jpeg", redirected: false, status: 403, ok: false, …}
body: (...)
bodyUsed: false
headers: Headers {}
ok: false
redirected: false
status: 403
statusText: "Forbidden"
type: "cors"
url: "https://abc-profile-images.s3-ap-southeast-1.amazonaws.com/https://abc-profile-images.s3.amazonaws.com/1601273978.331.jpeg"
__proto__: Response
Following is my code:
import { deleteFile } from "react-s3";
import config from './s3config';
const options = {
accessKeyId: config.ID,
secretAccessKey: config.key,
region: config.region,
bucketName: config.name
}
const removeImage = (uri) => {
console.log('file : ', uri)
return new Promise((resolve, reject) => {
deleteFile(uri, options)
.then(result => resolve(result))
.catch(err => reject(err))
})
}
export {
removeImage
};
import { removeImage } from '../../common/imageDelete'
function MethodList(props) {
const removeMethod = (e, page) => {
let image = e.target.dataset.image;
removeImage(image)
.then(res => console.log('s3 delete result : ', res))
.catch(res => console.log('Image catch', res))
}
}
export default MethodList