2013-04-17 28 views
1

我上傳的文件是這樣的:如何上傳文件公開,未經授權下載可用嗎?

if (isset($_FILES[$name])) { 
     $service = new Google_DriveService($client); 

     //Insert a file 
     $file = new Google_DriveFile(); 
     $file->setTitle($_FILES[$name]['name']); 
     $file->setMimeType($_FILES[$name]['type']); 
     $file->setParents(array('imgs')); 

     $insertedFile = $service->files->insert($file, array(
      'data' => file_get_contents($_FILES[$name]['tmp_name']), 
      'mimeType' => $_FILES[$name]['type'] 
     )); 

     return $insertedFile; 
    } 

獲取insertedFile就象這樣:

Array 
(
    [kind] => drive#file 
    [id] => 1sASTlgG7IFzcZyTUihp53uJbppFtxLs_GK_V2jYwapE 
    [etag] => "vGmlhiWxP02tugPmRvLynwC_A0Y/MTM2NjE4NTYyNzQwOQ" 
    [selfLink] => https://www.googleapis.com/drive/v2/files/1sASTlgG7IFzcZyTUihp53uJbppFtxLs_GK_V2jYwapE 
    [alternateLink] => ... 

但是,當我去selfLink,我得到一個錯誤

{ 
    ... 
    "code": 403, 
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." 
} 
} 

什麼是正確的方法無需任何授權即可上傳文件?看起來像文件只能通過API獲得。

+0

該錯誤看起來像你超過了最大值。上傳限制。 –

+0

也許你超過了一些限制,不能再從你的賬戶下載任何文件而無需進行身份驗證? –

+0

不,我沒有豐富的上傳限制 – Luciuz

回答

0

如果要下載內容,請對下載URL進行經過驗證的請求。

// Get the contents of the file. 
$request = new Google_HttpRequest($file->downloadUrl); 
$response = $client->getIo()->authenticatedRequest($request); 
$content = $response->getResponseBody(); 
+0

sry,即時消息關於下載。我認爲上傳是成功的 – Luciuz

+0

對不起,我的壞。您是否嘗試下載文件內容?如果是這樣,請不要使用selfLink。 selfLink響應與文件的元數據。 –

+0

謝謝。 API就是一切。 – Luciuz

相關問題