File.create trigger.after runs before row is created

I have a custom trigger function that’s supposed to run after a file has been created.

    type: trigger.after
      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.

  query GET_FILE($fileId: String) {
    file(fileId: $fileId) {

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 :frowning:

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

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 & if for whatever reason you wanted to fetch the row in an “after” it should return the row and not null.

@eugene.antonevich could you help us with this one? Seems like a really weird behavior, right?

1 Like

Yes, of course, I will investigate why download url is null if runs in after trigger soon.
The downloadUrl is virtual field. It doesn’t exist in database. That’s why it doesn’t exist in But, we will discuss it with the team.

1 Like

Thanks for looking into this so fast! It’s a blocker for me.

The whole file comes back as null not just the downloadUrl.

even if I try to request e.g. the file name, the file still comes back as null.

Most likely you are creating file record from a parent mutation. And trigger is called before transaction commit. So, we will provide downloadUrl in the We will release it in the next couple of days


Yeah I was testing it from a parent mutation in the 8base console.

Thank you so much @eugene.antonevich, could you get back to me when it’s released :slight_smile:?


Yes, of course. I will let you know when it’s released


@MarkLyck We have released the fix. Now we provide downloadUrl in Let me know if you have questions about it.

1 Like

Thank you so much! That’s amazing.

1 Like