Back

[SOLVED] Event trigger

  • 0
  • Functions
Mahla
14 Dec, 2023, 12:13

hi everybody, I want to use Event for my file uploads. I want to save file data in the specific collection by adding files into the specific bucket. would you make an example of what I should do? I would appreciate any help to understand.

TL;DR
The user wants to trigger a function whenever a file is uploaded to a specific bucket in Appwrite. They were looking for the correct event trigger to use but couldn't find the right solution. Another user provided the correct event trigger, which is `buckets.[BUCKET_ID].files.*.create`. They also mentioned that the `createFile` function returns a `File` object with file metadata that can be used to store the data in a collection. The user also asked if there is a way to get the file from the form part in an Appwrite function, but there was no clear solution provided.
ideclon
14 Dec, 2023, 12:19

IIUC, you’re asking what the correct Event would be to trigger on file upload to a specific bucket.

I think it should be buckets.[BUCKET_ID].files.*

Mahla
14 Dec, 2023, 12:21

no i want file parameters i dont know what to write in function file. I use nodejs

ideclon
14 Dec, 2023, 12:22

Not sure what you mean by “file parameters”?

Mahla
14 Dec, 2023, 12:22

like size, name, type

ideclon
14 Dec, 2023, 12:24

Ah. I’m not 100% sure, but I’d check in req

Mahla
16 Dec, 2023, 11:32

I didn't find:(

Mahla
16 Dec, 2023, 11:34

May I ask one more question... is there any way to get file from form part in appwrite function? I want to get the file and add to storage in my function. but it says: Cannot read property 'pipe' of undefined

ideclon
16 Dec, 2023, 21:43

So you want to POST the files directly to a Function, then push to Storage from there?

ideclon
16 Dec, 2023, 21:43

Will try to have a look a bit later

Mahla
18 Dec, 2023, 11:50

sorry to answer late. thanks a lot for your response.

Mahla
18 Dec, 2023, 11:51

No I want to create a function and set the event to that. whenever I upload the file into the bucket, function triggers.

Mahla
18 Dec, 2023, 11:53

in that function, I get the file parameters (like size, name, ...) and create a document in my file_detail collection.

Mahla
18 Dec, 2023, 11:54

but the problem is that I cant find the data about the file that make the function run. there were hints like req. payload, ... but none of them work.

Guille
18 Dec, 2023, 12:42

createFile returns a File object with the file metadata: https://appwrite.io/docs/references/1.4.x/server-nodejs/storage#createFile

getFile does the same, you won't need an event to do that.

The workflow would be

  1. Upload file and wait the response to get metadata
  2. store the data in the collection you want
ideclon
18 Dec, 2023, 15:45

Those functions return the data to the code where you upload the Function. OP wants a Function to be triggered and needs to know the file details there.

ideclon
18 Dec, 2023, 15:51

I just checked, and I do indeed have a File object in req.body

Guille
18 Dec, 2023, 15:55

You're right

Guille
18 Dec, 2023, 15:56

The event should be: buckets.[BUCKET_ID].files.*.create to be triggered just when the file is created, you should get a File object as well

Mahla
19 Dec, 2023, 06:16

Thank you very much :appwriteheart: @ideclon @Guille

Guille
20 Dec, 2023, 11:56

[SOLVED] Event trigger

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more