reans's avatar
Level 2

Laravel how to get presigned url file created event

I am trying to implement some code to upload files to S3 using a presigned url. My frontend client will request a presigned url, and at some point before the link expires will upload that file.

Now I need to know if that file was uploaded successfully, and I know that AWS seem to allow event notifications: https://docs.amazonaws.cn/en_us/AmazonS3/latest/userguide/NotificationHowTo.html

Is there something in the Laravel S3 driver which helps with this? Or do I listen on a SQS queue?

0 likes
6 replies
martinbean's avatar

@reans Those docs tell you how events are emitted:

Amazon S3 supports the following destinations where it can publish events:

  • Amazon Simple Notification Service (Amazon SNS) Amazon SNS is a flexible, fully managed push messaging service. Using this service, you can push messages to mobile devices or distributed services. With SNS you can publish a message once, and deliver it one or more times. Currently Standard SNS is only allowed as an S3 event notification destination, whereas SNS FIFO is not allowed. For more information about SNS, see Amazon SNS.
  • Amazon Simple Queue Service (Amazon SQS) queue Amazon SQS is a scalable and fully managed message queuing service. You can use SQS to transmit any volume of data without requiring other services to be always available. In your notification configuration, you can request that Amazon S3 publish events to an SQS queue. Currently, Standard SQS queue is only allowed as an Amazon S3 event notification destination, whereas FIFO SQS queue is not allowed. For more information about Amazon SQS, see Amazon SQS.
  • AWS Lambda AWS Lambda is a compute service that makes it easy for you to build applications that respond quickly to new information. AWS Lambda runs your code in response to events such as image uploads, in-app activity, website clicks, or outputs from connected devices. You can use AWS Lambda to extend other AWS services with custom logic, or create your own backend that operates at AWS scale, performance, and security. With Lambda, you can easily create discrete, event-driven applications that run only when needed and scale automatically from a few requests per day to thousands per second. Lambda can run custom code in response to Amazon S3 bucket events. You upload your custom code to Lambda and create what is called a Lambda function. When Amazon S3 detects an event of a specific type (for example, an object created event), it can publish the event to AWS Lambda and invoke your function in Lambda. In response, Lambda runs your function.

But if you’re uploading the file client-side, then you’ll know when the file is uploaded: the file will be uploaded when the request to upload the part(s) is finished.

reans's avatar
Level 2

I can certainly use SNS or SQS to listen to events, but I thought there might be something built it in to the S3 driver as it seems like a common use case.

I can't always know when the file is uploaded because I don't have access to all the clients, so I need a way to do this directly from S3.

martinbean's avatar

My frontend client will request a presigned url, and at some point before the link expires will upload that file.

@reans The “frontend client” will know when the file is uploaded… because the request will complete.

uploadFile().then(() => {
    // File was uploaded
});
reans's avatar
Level 2

I get you, but I don't write that code necessarily, and I can't put that requirement onto a third party.

martinbean's avatar

@reans Then you’ll need to set up an SNS topic and a HTTP subscriber (basically a webhook endpoint) in your app. You’ll receive an SNS message each time a new object is placed in the bucket.

The S3 driver doesn’t have anything for this because it’s outside the scope of “uploading files”. You need to create additional resources in your AWS account (the SNS topic, the subscriber endpoint in your app). This isn’t something a storage disk driver can do.

1 like

Please or to participate in this conversation.