I am using appwrite as backend for a blog website. In it I am storing images and fetching them using their id to display. However the browser is showing CORS restriction due to which image is not getting loaded on the website.
Below code is how I am using the image
<img
src={appwriteService.getFilePreview(post.featuredImage)}
alt={post.title}
className="rounded-xl"
/>
Below code is the definition of getFilePreview function
getFilePreview(fileId){
return this.bucket.getFilePreview(
config.appwriteBucketId,
fileId
)
}
I am using appwrite as backend for a blog website. In it I am storing images and fetching them using their id to display. However the browser is showing CORS restriction due to which image is not getting loaded on the website.
Below code is how I am using the image
<img
src={appwriteService.getFilePreview(post.featuredImage)}
alt={post.title}
className="rounded-xl"
/>
Below code is the definition of getFilePreview function
getFilePreview(fileId){
return this.bucket.getFilePreview(
config.appwriteBucketId,
fileId
)
}
Share
Improve this question
asked Feb 16 at 11:26
Noobmaster69Noobmaster69
11 bronze badge
1 Answer
Reset to default 0CORS errors usually happen because the project is missing a web platform that allows the app to connect to it. To add a web platform:
- Open your project in the Appwrite Console
- Scroll down to the Integrations section
- Click the Add platform button
- Select Web app
- Enter the hostname for your app
Besides the web platform, other reasons you may get this error are:
- lack of access due to permissions on the bucket or file
- incorrect project, bucket, or file id
Reference: https://appwrite.io/blog/post/cors-error