0

I am trying to upload a file to an account via Egnyte API. The CURL command says:

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

Can someone, tell how can I post it via PHP and get the JSON response as returned by the CURL call?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Nick M
  • 31
  • 6
  • Go look up the parameters used in the cURL man page, and compare with the options description of the cURL extension in the PHP manual. – CBroe Nov 02 '14 at 17:10

2 Answers2

2

I finally resolved it. Apologies for posting the solution lat. Below, is the function I created to upload the files to the server:

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);
}

Please do let me know n case of any issues/problems if anyone faces. I can help out.

FYI:

You can also contact for:

  1. how to get the oauth token.
  2. list the folders for your egnyte account onto your website's page.
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
Nick M
  • 31
  • 6
1

Egnyte has sample code showing how to upload a file using PHP and curl available here: https://developers.egnyte.com/samplecode.

Take a look specifically at the EgnyteClient.php file in the Anonymous PHP Uploader sample.

The curl request you posted is the sample from the website and is intended to be run from the command line. To use it on your domain, make sure you do the following:

  • Change the token 2v8q2bc6uvxtgghwmwvnvcp4 to the one you obtain from the authentication endpoint.
  • Update references to the sample 'acme' domain to your Egnyte domain.
  • Change the path for the file you are uploading and the path for where you want it to be uploaded in Egnyte.
  • 1
    I did all this but the file does not get uploaded. The file does not get listed in the folder on the egnyte website even if the scripts says "successful". I checked the folder names ad locations are correct in the script and I am checking the same folder on the egnyte website as well. I need this is wordpress eventually. – Nick M Nov 03 '14 at 04:58