Как загрузить файл в Amazon Cloud Drive?

Я хочу загрузить файл на Amazon Cloud Drive. Может кто-нибудь помочь мне отформатировать эту команду с помощью curl

Описание API:

Загрузить файл
Загружает содержимое файла вместе с информацией о его метаданных.

POST : {{contentUrl}}/nodes?suppress={suppress}

suppress : (Optional)

deduplication: disables checking for duplicates when uploading

Параметры тела:

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

Запрос образца:

POST /cdproxy/nodes?localId=testPhoto
HTTP/1.1
Host: content-na.drive.amazonaws.com
Authorization: Bearer
Atza|IQEBLjAsAhReYeezFcFdYzqrFOJGv3EG

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="metadata"
{"name":"fooo.jpg","kind":"FILE"}
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="content";
filename="db5df4870e4e4b6cbf42727fd434701a.jpg"Content-Type: image/jpeg

----WebKitFormBoundaryE19zNvXGzXaLvS5C

cURL Запрос:

curl -v -X POST --form
'metadata={"name":"testVideo1","kind":"FILE"}' --form
'content=@sample_iTunes.mp4'
'https://content-na.drive.amazonaws.com/cdproxy/nodes?localId=testVideo1&suppress=deduplication'
--header "Authorization: Bearer
Atza|IQEBLjAsAhQ5zx7pKp9PCgCy6T1JkQjHHOEzpwIUQM"https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes

1

Решение

finally i found how to format this curl request :
========================================================================$filename = basename($_FILES['file']['name']);
$filename = md5(time() . rand(1111, 9999)) . '-' . $filename;
$localid = md5(time() . rand(1111, 9999));
$tmp_name = $_FILES['file']['tmp_name'];
move_uploaded_file($tmp_name, './uploads/' . $filename);
$f = realpath('./uploads/' . $filename);
$url = 'https://content-na.drive.amazonaws.com/cdproxy/nodes?localId=' . $localid . '&suppress=deduplication';
$cfile = $this->getCurlValue($f, 'image/jpeg', time() . $filename);

$fields = array('metadata' => json_encode(array('name' => $filename, 'kind' => 'FILE')), 'content' => $cfile);
$headers = array('Authorization: Bearer ' . $this->session->userdata('access_token'),
'Content-Type: multipart/form-data',
'Host: content-na.drive.amazonaws.com',
);

$curl = curl_init();

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($curl);

curl_close($curl);

$filename = basename($_FILES['file']['name']);
$filename = md5(time() . rand(1111, 9999)) . '-' . $filename;
$localid = md5(time() . rand(1111, 9999));
$tmp_name = $_FILES['file']['tmp_name'];
move_uploaded_file($tmp_name, './uploads/' . $filename);
$f = realpath('./uploads/' . $filename);
$url = 'https://content-na.drive.amazonaws.com/cdproxy/nodes?localId=' . $localid . '&suppress=deduplication';
$cfile = $this->getCurlValue($f, 'image/jpeg', time() . $filename);

$fields = array('metadata' => json_encode(array('name' => $filename, 'kind' => 'FILE')), 'content' => $cfile);
$headers = array('Authorization: Bearer ' . $this->session->userdata('access_token'),
'Content-Type: multipart/form-data',
'Host: content-na.drive.amazonaws.com',
);

$curl = curl_init();

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($curl);

curl_close($curl);

function getCurlValue($filename, $contentType, $postname) {
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $contentType, $postname);
}

// Use the old style if using an older version of PHP
$value = "@{$this->filename};filename=" . $postname;
if ($contentType) {
$value .= ';type=' . $contentType;
}

return $value;
}
0

Другие решения

Других решений пока нет …