I have a custom trigger function that’s supposed to run after a file has been created.
HANDLE_FILE_UPLOAD:
type: trigger.after
handler:
code: src/triggers/HANDLE_FILE_UPLOAD/handler.ts
operation: File.create
The event that’s passed to this trigger, unfortunately, doesn’t include a downloadUrl (which would be super handy!)
So instead I run a query to the File table to fetch the file’s downloadUrl using the fileId fieId in the event.
const GET_FILE_DOWNLOAD_URL = `
query GET_FILE($fileId: String) {
file(fileId: $fileId) {
downloadUrl
}
}
`;
This works fine in isolation after a file is created. It returns an object with the downloadUrl for the file.
However… When running this in the trigger.after it returns null
for the file
Why is the trigger.after running if the file doesn’t exist yet? I would expect this to run after the file exists so I can fetch it, or even better, have the downloadUrl and other values in the event.data
my API token Role does have access to CRUD all fields on files.
[EDIT] tried adding a 5 second await before fetching the row and it still comes back as null.
[EDIT] tried adding a 20 second await and the function timed out.
[EDIT] tried adding a 10 second await before fetching the row and it still comes back as null.
The preview even exists at that point, so I’m not sure why I shouldn’t be able to Query the file?
When I fetch it manually after a file upload using the fileId, it works fine.
Expected behaviour:
downloadUrl should be in the event.data & if for whatever reason you wanted to fetch the row in an “after” it should return the row and not null.