Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
vibh
8 years agoExplorer | Level 3
API V2 Upload Limit
Hi, I am trying to upload the file to Dropbox using API v2 in PHP using curl. I am getting a 413 error response from the Dropbox server (Request entity too large). So what is the limit to upl...
Greg-DB
Dropbox Community Moderator
8 years agoI don't have a sample implementation for using upload sessions in PHP unfortunately.
Can you print out the full HTTP response body you're getting? It should contain a more detailed error message indicating the issue. If you still need help, please also share the code you have so far so I can take a look, in addition to the full error.
Can you print out the full HTTP response body you're getting? It should contain a more detailed error message indicating the issue. If you still need help, please also share the code you have so far so I can take a look, in addition to the full error.
vibh
8 years agoExplorer | Level 3
Hi,
Thanks for your response. Below is my code what I am using.
$api_url = 'https://content.dropboxapi.com/2/files/upload_session/start';
To above my code is:
$headers = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"close"=>false,
)
),
'Content-Type: application/octet-stream'
);
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
$path = $destPath . $to_zip_folder;
//echo $path;die;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
response === {"session_id": "AAAAAAAAAFXd8SqjQyOldQ"}
http_code === 200
$api1_url = 'https://content.dropboxapi.com/2/files/upload_session/append_v2';
To above API my code is:
$headers1 = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"cursor"=>$w,
"close" => false,
)
),
'Content-Type: application/octet-stream'
);
//print_r($headers1);die;
$ch = curl_init($api1_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers1);
curl_setopt($ch, CURLOPT_POST, true);
$path = $destPath . $to_zip_folder;
//echo $path;die;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
response === null
http_code === 200
$api2_url = 'https://content.dropboxapi.com/2/files/upload_session/finish';
To above API my code is:
$headers2 = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: ' .
json_encode(
array(
"cursor"=>$w1,
"commit"=>$q,
)
),
'Content-Type: application/octet-stream'
);
// print_r($headers2);die;
$ch = curl_init($api2_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers2);
curl_setopt($ch, CURLOPT_POST, true);
$path = $destPath . $to_zip_folder;
//echo $path;die;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp,$filesize));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
http_code === 413
if I use
curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp,$filesize));
then status_code = 413.
if I use
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
then it will save 0-byte file.
please suggest what curl should be for these three API?
Please help.
- Greg-DB8 years ago
Dropbox Community Moderator
If you're getting a 413, it indicates that you're passing too much data per request. For each of these three endpoints, you shouldn't pass more than 150 MB per request, per the documentation:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start
https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2
https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish
(In practice, you may want to pass much less than that per request, e.g., 8 MB.)
In short, you should send just a portion of the file in each request, using as many requests as necessary to send the entirety of the file across one upload session.
There's an example in the Java SDK that can serve as a good example of how this logic should work:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/upload-file/src/main/java/com/dropbox/core/examples/upload_file/Main.java#L92
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!