Skip to main content
Included with the Pinata SDK is the pinata/react package which comes with a hook you can use to upload files and a convert helper function for converting CIDs into IPFS Gateway URLs.

Installation

Install the Pinata SDK

Usage

Import at the top of your desired page or component
Inside your page or component use the hook to extract methods and state
Keep in mind that states like pause, resume, or progress are only available on files over 90 MiB that automatically engage resumable uploads through TUS.
Return types for useUpload
To upload a file you must already have a server setup that returns a Presigned URL. Then you can pass it into the upload method like so.
Below are the available UploadOptions that can be passed into upload
Once a file is uploaded the uploadResponse will contain either the full upload response or just the CID if your file was over 90 MiB and utilized TUS resumable uploads. If Pinata is still processing a large file when its last chunk arrives, the hook waits until the file is registered before setting uploadResponse, so loading stays true after every byte is sent. Pass waitForCid: false to skip that wait: uploadResponse is then the CID Pinata sent with the last chunk, or null if it wasn’t available yet, and registration can still fail afterwards. The convert helper can be used to turn a CID into a URL like so:
Below is a full example of implementing the useUpload hook with progress and abilities to pause and resume the upload.

Questions

Please contact us if you have any issues!