[SOLVED] My function runs twice on create file event when it's size is greater than 5mb
- 0
- Functions
- Web
- Storage
- Cloud

def main(req, res): """This function transcribes any audio file that is put into the bucket audio-files""" # Setup of various services client = Client() ( client.set_endpoint(req.variables.get("APPWRITE_FUNCTION_ENDPOINT", None)) .set_project(req.variables.get("APPWRITE_FUNCTION_PROJECT_ID", None)) .set_key(req.variables.get("APPWRITE_FUNCTION_API_KEY", None)) )
storage = Storage(client)
# Get the event data
event_data = json.loads(req.variables.get("APPWRITE_FUNCTION_EVENT_DATA", None))
event_name = req.variables.get("APPWRITE_FUNCTION_EVENT", None)
return res.json(
{
"event_name": event_name
}
)
I have the following functin it runs twice each time I run it on trigger of an event when a file is created in the bucket. I am uploading via the appwrite cloud console.
Get following as event
in respnse of both {"event_name":"buckets.647b122c985261158060.files.647f2a9b73d3aca5f718.create"} {"event_name":"buckets.647b122c985261158060.files.647f2a9b73d3aca5f718.create"}
This happens when the file is more that 5mb

Ohh

This happens when the file is more that 5mb
Make sense now.

Because when the file is more then 5MB the upload will dived to 5MB chunks

But I uploaded 1 file the event should not be fired twice

Is it a bug

Mmm, could be But maybe pepole like to track the upload progress..

For now what you can do is to check the chunkTotal
and chunkUploaded
in the event_data
object to know if the upload has finished


Is there any other way to track progress of the upload

Within functions? I don't think so

In client sdk

You can tap into the onProgress
method
https://github.com/appwrite/sdk-for-web/blob/master/src/services/storage.ts#L155
Like so:
storage.createFile('[BUCKET_ID]', '[FILE_ID]', document.getElementById('uploader').files[0], null, (prg)=>{
console.log(prg);
});

thanks for your effort

I will write a workaround for the evebts problem.

My function runs twice on create file event when it's size is greater than 5mb

but just for future if there is separate way of progress tracking. Shouldn't create fire a single event on file creation of more than 5mb

I don't think so, No.

Here's the related issue. feel free to 👍🏼 https://github.com/appwrite/appwrite/issues/4507
For now, you can check if chunks uploaded == chunks total in your function

Thanks steven

were you able to write a workaround for tracking the upload progress?

I am working on a project and i need to track the progress of the file upload

Please create a new <#1072905050399191082> post rather than posting in an old thread

[SOLVED] My function runs twice on create file event when it's size is greater than 5mb
Recommended threads
- Network error when attempting to fetch r...
Hi, I am trying to modify some database data in the console for testing but keep getting this error. I am on the appwrite cloud and have already tried clearing ...
- Having errors migrating to cloud
Project will not migrate compeltely
- Appwrite realtime stopped working all of...
In our production environment, Appwrite Realtime suddenly stopped working and no updates are coming through , can you confirm if there are any known issues?
