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 agoIt sounds like you're using /2/files/upload. That endpoint does have a file size limit of 150 MB.
For larger files, you should use upload sessions instead.
This works the same way for both paid and free accounts.
vibh
8 years agoExplorer | Level 3
Hi Greg,
Thanks for your response. please suggest how to use session with the curl in PHP.
An example of the same would be great because I am not able to implement it correctly after so many trials.
I changed my API URL: https://content.dropboxapi.com/2/files/upload_session/start
it gives "error in call to API function"
this is my header code
$headers = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: ' .
json_encode(
array(
"path" => '/' . basename($destPath . $to_zip_folder),
"mode" => "add",
"autorename" => true,
"mute" => false
)
),
'Content-Type: application/octet-stream'
);
Thanks in advance.
- Greg-DB8 years ago
Dropbox Community Moderator
I 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.- thelwang8 years agoHelpful | Level 7
vibh,
You seem to be doing things all yourself with curl. It might be easier for you to use some PHP bindings to the Dropbox API that someone else has made.
There doesn't seem to be an official Dropbox PHP binding, but this looks popular and sort of active on github: https://github.com/kunalvarma05/dropbox-php-sdk
You can see it uses upload sessions so that you can upload files larger than 100MB piece by piece://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php#L780
To install it, full their instructions here. You might first have to install php composer to use this though, documentation for that is here.
If you're getting stuck on implementing an API just from the HTTP spec...I'd really recommend using an SDK since you'll likely just continue to have problems as you start using other Dropbox API features.
- vibh8 years agoExplorer | Level 3
Hi,
Thanks for your response.
$api_url = 'https://content.dropboxapi.com/2/files/upload_session/start';
to above API 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, 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);response === {"session_id": "AAAAAAAAAFAB2YI_TkrUgw"}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'
);$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, 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);response === null
http_code === 200
$api2_url = 'https://content.dropboxapi.com/2/files/upload_session/finish';
to above 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'
);$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
Please help.
- vibh8 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!