如何通过api上传到Google Drive后获取文件的链接?

如何通过api上传到Google Drive后获取文件的链接?

问题描述:

我遵循本指南。我能够上传图片到我的谷歌驱动器,但我无法获得文件的路径。如何通过api上传到Google Drive后获取文件的链接?

https://gist.github.com/ivanvermeyen/cc7c59c185daad9d4e7cb8c661d7b89b

// Get img that was uploaded to my server 
$img = request()->file('img'); 

// Save that image to my google drive 
Storage::disk('google')->put('img.png', fopen($img, 'r+')); 

// ?? how do I get the path to the file so I can save it in my database? 

你看着它的laravel文档中?

https://laravel.com/docs/5.5/filesystem#file-urls

为您的代码,你应该这样做:

use Illuminate\Support\Facades\Storage; 

$url = Storage::disk('google')->url('img.png'); 

dd($url); 
+0

的img.png是文件的唯一名称。所以如果我这样做,那么它只会保存一个空文件。该文件是$ img,并将其另存为img.png – jeff923

+0

要获取url,您应该使用该文件的名称,那有什么问题?你试过了吗?也许在最后一行之后添加一个'dd($ url)' – PKeidel