2

I'm having trouble allowing files (non-shared) to be downloaded from a Google Drive account. I've created a listing using the php drive sdk and would like to provide authorised links to download the files using a generated access token. I've got downloads working with links like this:

https://www.googleapis.com/drive/v3/files/[fileid]?alt=media&access_token=[access_token]

The problem is that whenever a file is downloaded, it is named [fileid].[extension], rather than the real file name that appears in Drive.

I've tried adding the download="[real filename]" into the a link to suggest the correct filename, but it's being ignored in all the browsers I've tried.

I've got an alternative working that gets the file piece by piece server side and echoes it out as a file via php, but I'd prefer for downloads to be straight from Drive to the user.

Rich Heath
  • 21
  • 3
  • This might provide a solution http://stackoverflow.com/questions/283956/is-there-any-way-to-specify-a-suggested-filename-when-using-data-uri – pinoyyid May 03 '16 at 12:05
  • Gave it a go, but it didn't work. I think this only works with small files - I should have mentioned that the files I want to download may be pretty big (>100mb). – Rich Heath May 03 '16 at 12:58
  • there shouldn't be any dependency on size. – pinoyyid May 03 '16 at 13:54
  • If we're talking about the data: parameter inside the url then as far as I can tell, that only works with small files (I wouldn't want to print out the entire data for each file inside the link. – Rich Heath May 03 '16 at 14:39
  • If we're talking about the download="somefilename" part then that doesn't work and seems to be related to the access_token variable. As soon as "&access_token=####" is added to the url it stops using the download parameter and reverts to the id of the file (regardless of whether or not the access token is valid) - very strange! – Rich Heath May 03 '16 at 14:41
  • I think the problem with the download="" parameter is caused by the url redirecting after it has checked the token. Therefore if [this](http://stackoverflow.com/questions/27136539/set-name-of-the-download-file-even-if-download-link-redirect-to-another) is anything to go by, you can't change the name of the resulting file. Therefore, does anyone have a good way of downloading a file from google drive without needing the file to be viewable with the link? – Rich Heath May 03 '16 at 15:09
  • "seems to be related to the access_token variable". If that's the case (I doubt it) try setting the access token into an http Authorization header instead. – pinoyyid May 04 '16 at 04:06
  • No, it definitely is the access token, or rather what happens when it gets a valid access token. I tried with both valid and invalid tokens, and only when it receives a valid token does it redirect to the download and then ignore the "download" parameter. The same would happen if you sent a header I'm sure, as it's the redirect that is the problem, rather than the request. I think this is a dead end, so I'll have to look at alternative download methods. Thanks anyway. – Rich Heath May 04 '16 at 06:28

0 Answers0