0

First way to download:

  1. https://www.googleapis.com/drive/v3/files/1YIH4zfM0P1xa-_mfZNGiIY8qZrIEt-rF/?key=API_KEY&alt=media

Putting my API KEY in the link it gives me ability to download the file directly from my google drive.But I don't want to give my API_KEY to the users.

2.I can also access my drive another way: (using nao-pon/flysystem-google-drive)

Route::get('/download/{rest?}', function ($rest) {
    $metadata = Storage::cloud()->getMetadata($rest);
    $readStream = Storage::cloud()->getDriver()->readStream($rest);

    return response()->stream(function () use ($readStream) {
        fpassthru($readStream);
    }, 200, [
        'Content-Type' => $metadata['mimetype'],
        'Content-disposition' => 'attachment; filename="'.$metadata['name'].'"', // force download?
    ]);
})->where('rest','(.*)');

This way I don't have to use api_key but the server has to download the whole file it's a stream but still that uses server resources.

On the other hand https://www.googleapis.com/drive/v3/files/1YIH4zfM0P1xa-_mfZNGiIY8qZrIEt-rF/?key=API_KEY&alt=media needs Content-Type and File name as it doesn't have on it.And also I have no idea how to hide the api key.

So what do you suggest.Is there any other way not to response()->stream to not download the whole file by stream through server and then send it to the user?Multiple users downloading the files would use all the bandwidth,so the download speed drops so fast.

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
Steve Moretz
  • 2,758
  • 1
  • 17
  • 31
  • In your situation, the file is downloaded using API key. In this case, the file is publicly shared. And you want to hide the API key. If my understanding is correct, how about downloading without API key? For this, is this method useful? https://stackoverflow.com/a/48133859/7108653 – Tanaike Feb 14 '20 at 23:47
  • @Tanaike Hi thank you for the response.But in some cases like mine we might not want to share the file publicly and that's why we use the api key. – Steve Moretz Feb 15 '20 at 13:10
  • Thank you for replying. Unfortunately, I couldn't understand about your replying. This is due to my poor skill. I deeply apologize for this. – Tanaike Feb 15 '20 at 23:07
  • @Tanaike It's simple if you want to share a file publicly you can download it without api key.But if it's private then you must include the api key in the link so google drive knows you have permission to download the file. – Steve Moretz Feb 16 '20 at 08:04
  • Is putting the Share setting to 'available to anyone with the link' not a suitable option? This way the files aren't publically searchable but also those who have the link can view and download them? – Rafa Guillermo Feb 17 '20 at 10:14

0 Answers0