ivanvermeyen / laravel-google-drive-demo

Laravel & Google Drive Storage - Demo project with Laravel 5.4
403 stars 155 forks source link

Upload a file to drive and then retrieve the file ID to store in database #78

Open felix2056 opened 4 years ago

felix2056 commented 4 years ago

How do I do this please?

ivanvermeyen commented 4 years ago

Hello,

In the demo I just do a listContents and then search for the uploaded file name. Unfortunately, Laravel's put method doesn't return the file ID and this will also not work well if you have duplicate file names.

I believe you can use the underlying nao-pon/flysystem-google-drive package more directly and get some more optimal return values. I'm not very familiar with the underlying API tho, so you'll have to check with the package directly.

felix2056 commented 4 years ago

Thanks. I just throw an exception if the file being uploaded has the same name and extension with another one already on drive so that way I solved my duplicate file name problem and can now safely fetch files via name. It's not the cleanest approach but it works for me

ivanvermeyen commented 4 years ago

This method seems to return the file meta data.

https://github.com/nao-pon/flysystem-google-drive/blob/37f4bded24c4e63a88d9fc8bd483b654aef992f0/src/GoogleDriveAdapter.php#L197-L210

This:

dd(Storage::cloud()->getAdapter()->write('test.txt', 'Hello World', new \League\Flysystem\Config([])));

Gave me:

[
  "name" => "test.txt"
  "type" => "file"
  "path" => "XXXXXXXXXXXXXXXXXXXXX"
  "filename" => "test"
  "extension" => "txt"
  "timestamp" => 1579962626
  "mimetype" => "text/plain"
  "size" => 11
]
sr2ds commented 2 years ago

@ivanvermeyen thank you, my friend!