Back

[SOLVED] FIle Upload: CORS Error policy

  • 0
  • Web
Emilson
29 May, 2023, 04:34

client .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('647170480f75d7bd5b41') // Your project ID ;

methods: { handleFileUpload(event) { this.file = event.target.files[0]; }, async submitFile() { try { const response = await storage.createFile('64717d445b7a640fc647', ID.unique(), document.getElementById('file').files[0]); console.log(response); // Success } catch (error) { console.log(error); // Failure } }

}

TL;DR
The user was experiencing a CORS error when trying to upload a file. They received a "Storage bucket with the requested ID could not be found" error. They suspected that the project ID was the issue. The user checked their bucket settings and confirmed that everything looked fine. They also confirmed that the bucket was inside the project and had the necessary permissions. They shared a screenshot of their console, which showed an AppwriteException and a 404 error for the file upload request. The user also mentioned that they were receiving a CORS error, stating that "No 'Access-Control-Allow-Origin' header is present on the requested resource." Solution:
Binyamin
29 May, 2023, 04:34
TypeScript
import { Client, Storage, ID } from "appwrite";
Binyamin
29 May, 2023, 04:35

Like this

Emilson
29 May, 2023, 04:35

Alright

Emilson
29 May, 2023, 04:36

Still having the same CORS error : Acess to XMLHttpRequest at 'https://cloud.appwrite.io/v1/storage/buckets/64717d445b7a640fc647/files' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Emilson
29 May, 2023, 04:36

When i tried to upload

Binyamin
29 May, 2023, 04:37

What else do you get in the console? As localhost should be enabled

Emilson
29 May, 2023, 04:38

These are what I'm seeing on my console

AppwriteException: Network request failed at Client.eval (webpack-internal:///./node_modules/appwrite/dist/esm/sdk.js:423:23) at Generator.throw (<anonymous>) at rejected (webpack-internal:///./node_modules/appwrite/dist/esm/sdk.js:42:65) browser-ponyfill.js:518 POST https://cloud.appwrite.io/v1/storage/buckets/64717d445b7a640fc647/files net::ERR_FAILED 404 eval @

Binyamin
29 May, 2023, 04:40

So it's still 404

Can you check two things

  1. That this bucket is indeed inside this project and it has the necessary permissions.
  2. Share a screenshot of the preview tab inside the network tab
Emilson
29 May, 2023, 04:43

Yes.

Please can you explain what you meant in 2 ?

Emilson
29 May, 2023, 04:48
Emilson
29 May, 2023, 04:48

This is it, it's not showing any data

Binyamin
29 May, 2023, 04:48

And the one after?

Emilson
29 May, 2023, 04:49

Same input

Binyamin
29 May, 2023, 04:53

Everything looks allright. Can you share your bucket settings screen?

Emilson
29 May, 2023, 04:53

I ticked all

Emilson
29 May, 2023, 04:54
Binyamin
29 May, 2023, 04:56

Is the URL is like this? console/project-647170480f75d7bd5b41/storage/bucket-64717d445b7a640fc647/settings With this IDs?

Emilson
29 May, 2023, 04:57

Yes it is

Binyamin
29 May, 2023, 04:58

When I'm running this credentials it having problem finding the project ID

Emilson
29 May, 2023, 05:00

So the project ID is the issue ?

Emilson
29 May, 2023, 05:00

This the error i always get when i click to read the error:

{"message":"Storage bucket with the requested ID could not be found.","code":404,"type":"storage_bucket_not_found","version":"0.10.22"}

Emilson
29 May, 2023, 05:25

Hello @Binyamin i have solved it

Drake
29 May, 2023, 07:30

[SOLVED] FIle Upload: CORS Error policy

Binyamin
29 May, 2023, 12:42

Cool πŸ‘πŸ‘

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more