Hi, I am new to Appwrite and I am trying to upload files using a POST HTTP request to a function, which processes the file and store it in the storage system. Is it possible to do this? I don't see there's a files or form attribute of the context object, and posting through body doesn't seem to work. Is there any way I can upload files to a function? Or should I do this in the first place?
Hi @Row0 why you want to use a function and not the client SDK? What is your use case?
Hi! So basically what I want is to process the files my user uploads (compression, filtering, etc.) before saving them to the storage.
What appwrite version are you using?
I'm using the web version
What I would do in your case, as function only accept a string as payload, convert the file in base64 and send it as JSON with the rest of your data.
You can do with something like this:
const convertBase64 = (file) => {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.readAsDataURL(file)
fileReader.onload = () => {
resolve(fileReader.result);
}
fileReader.onerror = (error) => {
reject(error);
}
})
}
const base64 = await convertBase64(file)
honestly, i would just use 2 separate buckets, upload to 1 bucket, have a function that triggers on upload, process the file, and then store it in another bucket for serving.
Thank you! I think I'll stick with this approach.
[CLOSED] File upload to functions
Recommended threads
- script "build" was terminated by signal ...
Heyo, For some reason, my Next.js 16.0.10 version does not build properly. Here is the last logs: ``` 1063 packages installed [22.54s] $ next build ⚠ No build...
- Bug: Cloud Function On Schedule Didn't R...
Heya I have a cloud function with this cron `0 17 * * *` to run at 9AM PT every day. I have not touched this since I set it up, and it has been working fine s...
- functions
Code for function not being created in Github. Permissions are set correctly, repository is created, however no code is in the created repository. Just trying...