ivanvermeyen / laravel-google-drive-demo

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

How to create a copy of a file #55

Open muffaddal opened 5 years ago

muffaddal commented 5 years ago

Hi can you upload a sample code to check how to create a copy of a file?

ivanvermeyen commented 5 years ago

Hi,

You should be able to use the copy method Laravel provides (I think).

Storage::cloud()->copy($original, $duplicate);

The problem is that it will need the original's file ID, not the actual filename. Same goes for any subdirectories of the duplicate filename/path.

Code on how to get the ID is already in the examples.

Hope this helps...

muffaddal commented 5 years ago

Thanks Ivan for the prompt response! However i achieved this by creating a new instance of Google_Service_Drive_DriveFile

$fileToCopy = new \Google_Service_Drive_DriveFile('fileId'); $fileToCopy->setName('filename'); $file = $service->files->copy($template->basename, $fileToCopy);

This is off topic, but do you have any idea on how to open the google doc in edit mode in an iframe, from your web app?

ivanvermeyen commented 5 years ago

Ok, cool! I've been wanting to learn more about the underlying Google API ad perhaps create a more advanced wrapper around it, but at the moment I still can't prioritize it unfortunately. It's still on my things-to-explore list though.

For the embed editor, this worked for me: https://community.spiceworks.com/how_to/133689-how-to-embed-an-editable-google-docs-sheet

You create a share link that anyone with the link may edit the doc, and then you put it in an iframe. Downside is, anyone with the link can edit... which may not be secure enough?

I haven't found any other approach. Only read-only embed codes.