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

Add a ->storeDate() or a ->storeCustomData() feature #8

Closed bryanjamesmiller closed 3 years ago

bryanjamesmiller commented 3 years ago

Hey, my apologies for all the issue - again, thanks for the really great package! 😃

One thing we need actually is a way to store the date that each file was uploaded at. I know S3 stores this, but we can avoid retrieving that information from S3 and save some $$ if we store it in our DB. I also know if we used a model and relationship, we could then save the created_at date that way. However, it will keep our system simplest if we could just do something like this:

NovaS3MultipartUpload::make('Assets')
    ->storeName('file_name')
    ->storeDate()

At first, we thought we could just use the ->storeMeta() option but then we discovered this requires allowing the user to edit these fields - (a really cool feature!) but not exactly what we need. Maybe instead of specifying the date, you could even include a way to enter non-user meta data, like:

NovaS3MultipartUpload::make('Assets')
    ->storeName('file_name')
    ->storeCustomData(
                    [
                        'date' =>  now(),
                        'another_custom_value' => 'whatever'
                    ]
)

but either way would work for us and be a cool addition to the package.

ahmedkandel commented 3 years ago

Hey, it looks good, but not much precise. As the metadata will be passed first to the front-end and will have a time gap between creating the metadata and storing in the DB. So i think will be better if we implement a new set of features callbacks e.g. onBeforeSave(function ($data) {}) to be called before saving to DB to manipulate the data to be saved. Maybe also other callbacks that will give more flexibility to hook to other events.

ahmedkandel commented 3 years ago

@bryanjamesmiller check the new UI hide option in ->storeMeta(), Still the callbacks idea is better for security and precise but it needs more time to be implemented later on.

bryanjamesmiller commented 3 years ago

That looks awesome @ahmedkandel I will try this out as soon as I get a chance. Thanks for implementing it!

bryanjamesmiller commented 3 years ago

@ahmedkandel Just confirmed it's working like a charm. Thanks again for the great work on this package! If you want to bump the version number sometime soon that would be nice as currently I had to pull in from master. Many thanks again! 🎉