Server Action Not sequential (synchronious) with S3 Upload

Hey ya’ll,

I’m attempting to read a receipt from a store and put the info in a database. I’m doing an AWS S3 upload. It works great. I can upload no problem, and access the pictures later.

I’m also connecting with an API to read receipts. The API works great.

**However, when I put them together in one server action my results vary. **
Sometimes it works sometimes it doesn’t.

:face_with_monocle:
I discovered that if I upload a very small image file it works fine. If I upload a large image file the API for the receipt throws an error saying it cannot access the file, it’s not there.

In fact, if the API runs before the picture is uploaded the picture doesn’t finish uploading. If I turn off the API everything works fine. If I turn off the upload and assign the API to a file I know is on the server everything works fine.
:face_with_monocle:

That leads me to believe the server action is not running sequentially when an S3 upload is involved.

MORE DETAILS:
You can see the image here:

  1. I set a value for the file extension.
  2. I run an API to get a random number.
  3. I set a Value (“RandomNumber”) connected to that random number
  4. I set a Value that makes the filename a combination of the filename/sah256, timestamp, and rand number so the file name is unique
  5. I run the Sign Upload Url
  6. I set a Value called {{sign}} that comes from the uploader
  7. I insert the picture name into my database
  8. I set a Value of the ID of the picture in the DB
  9. I query the DB to get the info like filename and remote address of S3 Bucket
  10. I have a condition if/then…
  11. If the sign says, “YES I WORKED” then do this (why does this say yes when the upload didn’t finish?)
  12. Then I call the API to “Mindee” (the places that analyzes receipts)
  13. Then I Update the database with receipt information

image

Hi.
The condition in the screenshot is disabled. Is that how its configured, or just the screenshot is incorrect?
If condition is indeed disabled, the steps inside it will not run.

I have many complex SA, and so do many other devs… haven’t seen any issues with sequence of execution.
To debug, maybe add a RESPONSE step after the sign upload step and set {{sign}} as the response. You can move that step below the next one one by one to check where its failing and giving you inconsistent output.

Yes, I had that step temporarily disabled while testing.

I will try the response steps in the morning. Though, that’s kind of what I was trying to do by disabling each step and seeing what worked and what didn’t.

The upload and variables worked if I have the step above disabled. As soon as I enable that, it fails if I upload a large image.

I’ll try the response thing and see if I learn anything new! :+1:

Seems as though wherever I put the RESPONSE in this server action it stops the upload from completing.

So, a question:
Does a server action need to complete ALL the way for an S3 upload to work?

When you add a response step, the SA stops then and there.
No other steps execute after that.

1 Like

Yes, that’s right.

But, it didn’t matter where I put the RESPONSE - the S3 upload never completed as long as the RESPONSE was in there.

It’s very peculiar.
I’ve found a workaround - instead of hitting the API in the same SA I’ll wait for the “done” response then fire off another different SA. But, I’d still like to understand this.

Does an S3 upload in a SA need the SA to complete all the way before the upload is finalized?
That seems to be what I’m seeing.
So, if there are other steps that rely on the upload (to be 100% completed) you cannot put them in the same Server Action as the S3 Upload.

I did not implement this in my system I just recreated with some dump elements.
Why not set up the flow like this

I absolutely don’t know if it will work fyi since I don’t S3 to test it out but I do believe adding the condition right after the Set Value name url and setting that as the condition will allow that Sign Upload Url to finish process then the condition will run the other steps so long as that’s the case?

I’m not sure how you do the upload, but the Sign Upload Url doesn’t upload a file, it generates an url where you can upload it from the browser. To upload a file from the server you need to use the Put File action.

I’m having users upload a file from the browser.