react-s3bucket-upload

1.1.2 • Public • Published

react-s3bucket-upload

A react function for uploading images to amazon s3 bucket

Deps

##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
  }

Readme

Keywords

Package Sidebar

Install

npm i react-s3bucket-upload

Weekly Downloads

5

Version

1.1.2

License

ISC

Last publish

Collaborators

  • jihdeh