0
私はDropboxにファイルをアップロードするのに、空のファイルを作成するたびにPHPとCurlを使用しています。ここに私のコードは次のとおりです。Dropbox APIドキュメントサイズをアップロードしています。
// reading the remote file to get the file size...
$file = 'https://upload.wikimedia.org/wikipedia/en/5/58/Penny_test.jpg';
$ch = curl_init($file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$fileSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); // Response is 11201 bytes
// upload file to dropbox
$token = 'xxxxxxx'
$headers = [
"Authorization: Bearer ". $token,
'Dropbox-API-Arg: {"path": "/Penny_test.jpg", "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);
$file = 'https://upload.wikimedia.org/wikipedia/en/5/58/Penny_test.jpg';
$fp = fopen($file, 'rb');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$result = curl_exec($ch);
print_r($result); die;
ここで私が得ることの応答です:
{"name": "54.png", "path_lower": "/penny_test.jpg", "path_display": "/Penny_test.jpg", "id": "id:xxxxxxxxxxxxxxx", "client_modified": "2017-12-04T23:35:37Z", "server_modified": "2017-12-04T23:35:37Z", "rev": "bb3a7696db", "size": 0, "content_hash": "xxxxxxxxxxxxxxxxxxxxxxxxxx"}
なぜDropboxが私が間違っているの何このアップロード&から0サイズのファイルを取得していますか?
ありがとうございました。
1.あなたがあなたのサーバーからファイルを読み取ることができますか? 2.ファイルのサイズに 'CURLOPT_INFILESIZE'を設定しようとしましたか? – Dekel
はい、これを反映するために上記のコードを修正しました。 – LargeTuna