I use appwrite to store my images and I get them via a function that I export from 'appwrite.ts'. Then I use Svelte to display the image using the requested brand and name by calling it from the Svelte file, but when the website sees the await, it gives a 500 (Internal Server Error).
+page.svelte
<script lang="ts" type="module">
import { getImageURL } from '../../../appwrite'
</script>
<img src={(await getImageURL(brand, name))?.toString()} alt="">
appwrite.ts
export async function getImageURL(brand: string, name: string) {
if (browser) {
const promise = storage.listFiles('Images', [Query.equal('name', brand + " " + name + ".png")])
return await promise.then(async function (response) {
return (endpoint + `/storage/buckets/Images/files/${response.files[0].$id}/view?project=PCDatabase`).toString()
}), async function (error: any) {
console.log(error)
return (endpoint + '/storage/buckets/Images/files/6482e96a92473bfc9b5b/view?project=PCDatabse').toString()
}
}
}
I expect the code to work and return the URL without a 500 Error. I've tried removing the await in +page.svelte, but then it gives me back a [object Promise]. How do I fix this?