简体   繁体   中英

AWS S3 Storage put method

Hi I have an AWS S3 bucket I added the storage using amplify add storage. I can pull images from the public folder I made, for some reason though I can not put/add images. I want to specify the folder public/ when I run the put. I get a forbidden error ( SignatureDoesNotMatch ) right now might just be because I am not specifying the public folder or my permissions is not setup properly. Any guidance is greatly appreciated.

const uploadedImage = await Storage.put(imgsPreview[0].img)

Try this

const uploadedImage = await Storage.put(`${some_loaction}/${imgsPreview[0].img.name}`,imgsPreview[0].img, { contentType: "image/*" })

You alsoe can rename the file ${imgsPreview[0].img.name} . You can use uuid

import { v4 as uuid } from "uuid";

const uploadedImage = await Storage.put(`${some_loaction}/${uuid()}${imgsPreview[0].img.name.split(".").pop()}`,imgsPreview[0].img, { contentType: "image/*" })

So finally you can get you image under public/some_loaction/Your_file_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM