2014-11-02 31 views
0

我想通過Egnyte API將文件上傳到帳戶。 curl命令說:文件上傳Egnyte API

curl -v --request POST\ 
    -H "Authorization: Bearer 2v8q2bc6uvxtgghwmwvnvcp4"\ 
    --upload-file\ 
~/Desktop/test.txt https://acme.egnyte.com/pubapi/v1/fs-content/Shared/Documents/test.txt 

有人能告訴我如何通過PHP發佈,並得到JSON響應由捲曲調用返回的?

+0

查找cURL手冊頁中使用的參數,並與PHP手冊中cURL擴展的選項描述進行比較。 – CBroe 2014-11-02 17:10:03

回答

1

我終於解決了。抱歉發佈解決方案lat。下面,是我創建的文件上傳到服務器的功能:

require('functions/egnyte/lib/curl.php'); 
require('functions/egnyte/lib/curl_response.php'); 
require('functions/egnyte/EgnyteClient.php'); 

function doUpload() { 
    $domain = 'yourdomain'; 
    $folder = '/Shared/our folder name/'; 

    $oauthToken = 'your oauth token'; 
    $fileBinaryContents = file_get_contents($_FILES['filedata']['tmp_name']); 
    $fileName = $_FILES['filedata']['name']; 

    // instantiate an Egnyte Client with the domain and oAuth token for the user with which the upload will be performed 
    $egnyte = new EgnyteClient($domain, $oauthToken); 

    // perform the upload and get the response from the server 
    $response = $egnyte->uploadFile($folder, $fileName, $fileBinaryContents); 
} 

請不要讓我知道的任何問題/問題ñ情況下,如果任何人的面孔。我可以幫忙。

FYI:

您也可以聯繫:

  1. 如何獲得OAuth令牌。
  2. 將您的egnyte帳戶的文件夾列入您網站的頁面。
+0

如何獲取文件夾列表? – XXLend 2017-06-21 06:35:17

1

Egnyte提供了示例代碼,顯示如何使用PHP上傳文件以及curl可在此處獲得:https://developers.egnyte.com/samplecode

請專門查看Anonymous PHP Uploader示例中的EgnyteClient.php文件。

您發佈的curl請求是來自網站的示例,旨在從命令行運行。要在您的域名使用它,請務必做到以下幾點:

  • 更改令牌2v8q2bc6uvxtgghwmwvnvcp4你從authentication endpoint獲得一個。
  • 將示例「acme」域的引用更新爲您的Egnyte域。
  • 更改您要上傳的文件的路徑以及要在Egnyte中上傳文件的路徑。
+0

我做了所有這些,但文件沒有上傳。即使腳本顯示「成功」,該文件也不會列在egnyte網站的文件夾中。我檢查了文件夾名稱廣告位置在腳本中是正確的,我也檢查egnyte網站上的同一個文件夾。我最終需要這是wordpress。 – 2014-11-03 04:58:40