react-s3bucket-upload
v1.1.2
Published
An upload tool to s3
Downloads
58
Readme
react-s3bucket-upload
A react function for uploading images to amazon s3 bucket
##Usage
import uploadImage from "react-s3bucket-upload";
await uploadImage(this,
`/api/images`,
imageFile,
this.onReceiveDefaultUrls,
this.onFailImageLoading
);
###Parameters
The first parameter `(/api/images)`
- This is an endpoint which signs the request to s3, It's an endpoint on your end
to return such things as signature, policy, bucket....etc
const {
signature,
policy,
date,
bucket,
accessKeyID,
region,
urls
} = (await axios.get(`http://localhost:7000/api/images/${uiqueUUID}/signature?type=${type}`)).data;
where uiqueUUID is a unique uuid generated from this module
imageFile
- This is an object of the image selected, which contains, files name, datetime....
onReceiveDefaultUrls(function)
- This returns the urls to the images uploaded to s3 bucket amazon
For example
onReceiveDefaultUrls(formats) {
//set whatever state once urls are returned.
}
onFailImageLoading(function)
- If an error occures, it recives the error message and sends it back
For example
onFailImageLoading(error) {
//display error message
}