PinataCloud / pinata

The new Pinata SDK
https://docs.pinata.cloud/sdk
MIT License
8 stars 4 forks source link

fix: Removed Source header to fix CORS error #10

Closed stevedylandev closed 2 months ago

stevedylandev commented 2 months ago

The gateways.get method had an unnecessary Source header that was causing CORS issues in client side fetching. Removed the header and adjusted unit test.

Keref commented 3 weeks ago

It seems the issue is still there in latest version 1.5.0

stevedylandev commented 3 weeks ago

Hey @Keref! This issue was relevant pre v1 of the SDK when it was still used for IPFS (if you are looking to use IPFS, please checkout pinata-web3). Since v1.* is now using the Files API, it has to make an API call to create a signed URL using the PINATA_JWT, which should not be performed client side. With that said a CORS error might be expected as that's how the API was designed.

If you need to fetch content client side with the Files API, you have two options:

  1. Create a signed URL server side and return the URL to the client so it can fetch the content, as seen in this quick start guide.

  2. Add the file to a public group and fetch the file manually, eg:

const dataReq = await fetch(`https://${YOUR_GATEWAY_DOMAIN}/files/${FILE_CID}`)
const data = await dataReq.json() // depending on the content this could also be .text() or .blob()

Hope that clears it up but let me know if you have any other questions!