Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

CORS Errors When Trying to Fetch a File Using Capacitor

3 replies
Last updated: Jul 26, 2022

I am writing an app using Capacitor which allows you to use web tech in iOS/Android. But on iOS, the URL schema is capacitor://localhost/PAGE , etc. I am getting CORS errors when I try to fetch a file uploaded to Sanity because I cannot add capacitor://localhost as a valid CORS origin. I am getting

Failed to load resource: Origin <capacitor://localhost> is not allowed by Access-Control-Allow-Origin. Status code: 403

Jul 18, 2022, 7:21 PM

I am looking into this 🙂

Jul 26, 2022, 11:47 AM

So the team has answered and here is our solution:you can add the CORS via Sanity CLI:

sanity cors add <capacitor://localhost>
We might add the functionality in
sanity.io/manage but that’s low on the list, bc we have a solution at hand 🙂

Jul 26, 2022, 2:21 PM

I just added * for now which works but is a bit less safe, but our API is read-only anyway. I just wanted to make sure it got added to your ticket system. Thank you 🙂

Jul 26, 2022, 4:30 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.