Hi!
I have the following problem:
I want to create an appwrite function, let's say uploadImage. My request data could look something like this:
{
"name": "imageName",
"fileBytes": [
// File in bytes
]
}
My problem is, that when passing the file as bytes, I exceed the length that the req variable can have. So is there any other way to pass images/files to appwrite functions?
upload using the storage api and then fetch it in the function
I want to upload it inside the function
that's why *upload*Image
why? what's your use case? Passing a file to Create Execution is not a good idea
Explaining the real use case would be a bit too complex, but let's imagine you have an article. You write something and somewhere in between you add an image. What you need to do, is that you need to update the item in the collection that stores the article, telling it that this image id belongs to the article AND you need to create an item in the storage. Now, The images can be quite big, causes the following problem:
- I first update the database and then the storage. But here is the problem: Let's say the image upload takes 15minutes. If the connection interrupts during that period of time, the database has the information: This image belongs to me. But the image doesn't exist at all
- I first upload the image and then update the database item: This would make the problem even worse. If the database update also takes a bit, which may be the case, and the connection stops during database update, I have stored an image in the storage that isn't associated at all with any article, causing an unnecessary use of storage.
My solution: Using an appwrite function, so even if the connection breaks, it
- Stops updating at all (which is fine for me too)
- Continues updating, so no dead data exists.
This is a common scenario when dealing with files. I prefer creating the document first and then upload the file with the same id as the document. After the upload is complete, the function can update a status attribute on the document to indicate the upload was successful.
That's pretty much my approach with https://levelup.gitconnected.com/building-a-location-based-app-with-appwrite-48a2e2b6d4c2
Recommended threads
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...
- Appwrite (Dart SDK) (for package_info_pl...
Hi team! Many Flutter plugins now need package_info_plus 10.x and device_info_plus 13.x, but appwrite 25.4.0 still constrains package_info_plus: >=8.0.2 <10.0...
- Functions in cloud console not works
please advise as all of my runing functions on Appwrite console was working before , but now it give this error [Invalid `headers` param: Value must be a valid...