appwrite / sdk-for-web

[READ-ONLY] Official Appwrite Web SDK 🧑

Home Page:https://appwrite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug Report: Origin localhost not allowed when fetching file

lkoehl opened this issue Β· comments

πŸ‘Ÿ Reproduction steps

Running a local instance of appwrite, use Safari as a browser and fetching data from a link returned by getFileView

const url = storage.getFileView(BUCKET_ID, fileId);
axios
  .get(url.href)
  .then((response) => console.log(response))
  .catch((error) => console.log(error));

πŸ‘ Expected behavior

Returns the data from the file.

πŸ‘Ž Actual Behavior

[Error] XMLHttpRequest cannot load http://localhost/v1/storage/buckets/62e3ed0fc097798c4bfe/files/62e3ed7e4eafee1a50d1/view?project=625ec35b68a2dcb2d0fd due to access control checks.
[Error] Failed to load resource: Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. Status code: 200 (view, line 0)

🎲 Appwrite version

Version 0.9.x

πŸ’» Operating system

MacOS

🧱 Your Environment

No response

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

@lkoehl, thanks for raising this issue! πŸ™ I tried to reproduce your issue, but I was able to successfully fetch a markdown file and get the text. Would you please make sure your project ID is correct and use https for your endpoint?

@stnguyen90 thanks. It's works with Safari when setting the endpoint to https://localhost/v1. Maybe the README needs an update?

sdk-for-web/README.md

Lines 47 to 58 in cfc9baa

### Init your SDK
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
```js
// Init your Web SDK
const client = new Client();
client
.setEndpoint('http://localhost/v1') // Your Appwrite Endpoint
.setProject('455x34dfkj') // Your project ID
;
```

@gewenyu99, thoughts on making all of our examples use HTTPS since sometimes there's weird behavior when using HTTP (due to how browsers handle cookies and/or redirects)?

@gewenyu99, we seem to be inconsistent. Most are HTTPS except:

  1. swift-client
  2. dotnet
  3. web
  4. cli

I agree. I want to make everything https. This will be true esp. for cloud anyway. I have this written down in the doc contribution guide draft :)

Localhost and https can create issues on top without any configuration. We should double check that.

Thinking about local dev servers that connect to Appwrite which don't support https oob. Then you run into http -> https conflicts.

This issue only occurs in browsers, that's why non-browser sdks might target https.

Localhost and https can create issues on top without any configuration. We should double check that.

Thinking about local dev servers that connect to Appwrite which don't support https oob. Then you run into http -> https conflicts.

This issue only occurs in browsers, that's why non-browser sdks might target https.

I think the real solution will be when we have cloud ;)

Then we can just use the cloud URL as the default example.