cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: API V2 Upload Limit

API V2 Upload Limit

vibh
Explorer | Level 3

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 upload the file to Dropbox and Please let me know there is any limit on the paid account?

7 Replies 7

Greg-DB
Dropbox Staff

It 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
Explorer | 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-DB
Dropbox Staff
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.

thelwang
Helpful | 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.

vibh
Explorer | 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. 

vibh
Explorer | 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-DB
Dropbox Staff
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/dropb...
Need more support?