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
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- Can't login or deploy functions in Appwr...
Hello, since i updatet to the appwrite cli 6.1.0 i can't login or deploy functions with the cli. When i call the command: "appwrite get account --verbose" i ge...