我正在使用PHP从AWS S3获取我的对象,然后转身并将其上传到Dropbox。我可以从AWS成功获取对象,但是当我尝试将文件上传到Dropbox时,我只是一个空的Json响应,没有任何错误或任何错误。我知道我的$ dbToken(Dropbox令牌)工作正常,因为我可以使用相同的密钥来获取我的文件夹结构和列表文件。
当我尝试上传文件时,它只是空白。我认为这与AWS预签名URL有关。我是否需要发出Curl请求才能获取该URL的内容(在我的情况下为$ secureUrl)。不知道如何写这个以及如何将此文件放入Dropbox。谢谢你的帮助。
# ============================================
# Connect to AWS and get the Object
# This works fine...
# ============================================
$s3 = new S3Client([
'credentials'=>[
'key'=>xxxxxxx,
'secret'=>xxxxxxx,
],
'region'=>'us-west-2',
'version'=>'2006-03-01',
]);
$cmd = $s3->getCommand('GetObject', [
'Bucket' => xxxxxxx,
'Key' => xxxxxxx,
]);
$request = $s3->createPresignedRequest($cmd, '+60 seconds');
$secureUrl = (string) $request->getUri(); // get signed uri...
# echo $secureUrl; // if I echo this on the page, I can see the url, copy it and paste it into the browser and all works well...
# ============================================
# Connect To DropBox and Upload File...
# This is returning nothing in my output...
# ============================================
$dbToken = 'xxxxxxx';
$headers = [
"Authorization: Bearer ". $dbToken,
'Dropbox-API-Arg: {"path": "'.$secureUrl.'", "mode": "add", "autorename": true, "mute":false }',
"Content-Type: application/octet-stream"
];
$url = 'https://content.dropboxapi.com/2/files/upload';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
$path = $secureUrl;
$fp = fopen($path, 'rb');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$result = curl_exec($ch);
$data = json_decode(trim($result), TRUE);
echo '<pre>';
print_r($data); // the json response is empty...
echo '</pre>';