Am trying to build a web interface in PHP for Amazon Cloud Drive using their REST API. I was able to do Authentication, Login, Listing contents, Creating Folders, Deleting contents, Downloading Contents... but unable to do upload file action. The reason is i was unable to form proper request as like their document here... http://ift.tt/1En8lys
It says the body parameter of my request should be as follows...
Body Parameters:
Multi-form part
--------- metadata ------------
name (required) : file name. Max to 256 Characters.
kind (required) : "FILE"
labels (optional) : Extra information which is indexed. For example the value can be "PHOTO"
properties (optional) : List of properties to be added for the file.
parents(optional) : List of parent Ids. If no parent folders are provided, the file will be placed in the default root folder.
---------content ------------
File Bytes
they also added CURL would be following...
curl -v -X POST --form
'metadata={"name":"testVideo1","kind":"FILE"}' --form
'content=@sample_iTunes.mp4'
'http://ift.tt/1Nl96lB'
--header "Authorization: Bearer Atza|IQEBLjAsAhQ5zx7pKp9PCgCy6T1JkQjHHOEzpwIUQM"
this above stuff i have to form in my CURL request using PHP... the following is what am trying...
$url = 'http://ift.tt/1GFhBjO}';
$file_name_with_full_path = realpath('sample.jpg');
$fields['multipart'] = array();
$array1 = array(
'name' => 'testupload',
'content' => array(
'kind' => 'FILE',
'name' => 'sample.jpg',
'parents' => $parents
)
);
$array2 = array(
'name' => 'contents',
'contents' => @$file_name_with_full_path
);
array_push($fields['multipart'], $array1);
array_push($fields['multipart'], $array2);
$fields_string = json_encode($fields);
//$fields_string = $fields;
$httpheader = array( 'Authorization: Bearer '.$this->access_token);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($ch);
$httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
But the result am getting always is follows...
string(275) "HTTP/1.1 500 Internal Server Error
Content-Type: application/vnd.error+json
Date: Tue, 13 Oct 2015 06:03:39 GMT
Server: Amazon-Cloud-Drive
x-amzn-RequestId: b4f939ca-94ab-4444-a99a-165f6900d6c8
Content-Length: 30
Connection: keep-alive
{"message":"Internal failure"}"
Unable to upload file !
this is due to the wrong formation of the body parameter of request as per Amazon API team. But they couldn't be able to help as they were not into PHP development. Can someone help me to form the CURL request as same as what the above format says ?
Thank you so much guys.
Aucun commentaire:
Enregistrer un commentaire