Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Removed Source header to fix CORS error #10

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

stevedylandev
Copy link
Collaborator

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.

@stevedylandev stevedylandev merged commit 8bc1062 into main Aug 19, 2024
1 check passed
@Keref
Copy link

Keref commented Oct 21, 2024

It seems the issue is still there in latest version 1.5.0

@stevedylandev
Copy link
Collaborator Author

stevedylandev commented Oct 21, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants