ahmedkandel / nova-s3-multipart-upload

A Laravel Nova resource tool to upload files directly to Amazon S3. You can (upload | download | delete) single, multiple, small or big files.
MIT License
22 stars 22 forks source link

Upload complete callback #12

Closed flexgrip closed 3 years ago

flexgrip commented 3 years ago

Hello,

I currently have a video workflow that I built myself. My users chunk-upload a video and as soon as its done, the dropzone callback fires off a request to encode it.

Do you have any mechanisms in this package that would allow me to hit a callback when the upload is complete? If not, the only other way I can think to do it would be to listen for model events and hope I get them right so I don't encode a video more than once.

Thanks!

ahmedkandel commented 3 years ago

Hi @flexgrip, currently the package has no callback features. But we plan to add them soon. in the meantime you can follow one of the following approaches:

1- Use a Laravel model observer to invoke the workflow when the file_path gets saved on the model. 2- Use S3 Event Notification to invoke an AWS Lambda function when a new file is uploaded.

flexgrip commented 3 years ago

Sorry for the delayed follow-up. But just curious. With method #1 above, I get it. Just use a model observer and fire an event on model save. However, does that happen when the upload completes or whenever the user clicks "save" on nova page, saving the model?

For my use case, when a user uploads a video I need to send it off to our encoders to encode the video. But I don't want to make them save the entire model/nova page just to get the encoding to kick off.

Maybe I'll fork this and try adding my own callback to fire off the encoding. Any suggestions? Thanks again for this package.

ahmedkandel commented 3 years ago

The model observer will be invoked whenever the user saves/updates the nova resource, But you can specifically send the file to your encoder only if the file_path property is updated which means you will send the file just once.

To do so the observer updated method will receive the model as a parameter you can check if your file_path property is updated/dirty and then execute your logic:

public function updated($model)
{
    if ($model->isDirty('file_path') {
        // send the file to encoder
    }
}

You can even use a simple closure to do so.