gearbox-solutions / eloquent-filemaker

A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
https://gearboxgo.com
MIT License
54 stars 16 forks source link

Wrong filename when uploading file to container field #71

Closed alexandrosraikos closed 2 months ago

alexandrosraikos commented 2 months ago

NOTE: This might seem very similar to #70, but it concerns the original filename, not the array instance with the custom file name.

Dependencies

Description of the issue:

Uploaded form files (UploadedFile instances) don't get saved to containers with the proper original filename in the container fields. They are being saved with the temporary PHP blob upload name (phpXXXXX without extension).

Expected Behavior:

The file should be uploaded with its original file name.

Steps to reproduce:

  1. Retrieve a model instance with a container field.
  2. Set an UploadedFile on the attribute which reflects the container attribute.
  3. Save the model SomeModel->save()
  4. The saved file contains the temporary extensionless PHP filename instead of the desired name.

Additional Information

After a quick debugging session, I noticed that the file name retrieval in GearboxSolutions\EloquentFileMaker\Services\FileMakerConnection::uploadToContainerField uses $file->getFilename instead of $file->getClientOriginalName(). I can confirm that changing it locally did fix my issue, but just want to confirm with you.

Smef commented 2 months ago

This sounds like correct behavior, and is how saving and retrieving files works in general. Laravel stores an upload file and assigns it a random, temporary name. If you want to use the uploaded file's original name you should call the function to save it as such. For native laravel storage you'd use something like:

$file = $request->file('photo');
$file->store('uploads'.'/'.$file->getClientOriginalName());

if you wanted to save the file with the original name.

Here's an example for saving to a FileMaker container:

        $file = $request->file('photo');
        $pet = new Pet();
        $pet->photo = [$file, $file->getClientOriginalName()];
        $pet->save();