Hi,

I am using services module, rest and i love it. But I have run into issue with posting image larger than 800kB. Content length of this request is ~1000000.

I am using cURL here is sample code:

$image_data = array(
  'filesize' => filesize($filename),
  'filename' => basename($filename),
  'file' => base64_encode(file_get_contents($filename)),
  'uid' => $logged_user->user->uid,
);
$image_data = http_build_query($image_data);

// Define cookie session
$cookie_session = $logged_user->session_name . '=' . $logged_user->sessid;

// cURL
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); // Accept JSON response
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $node_data); // Set POST data
curl_setopt($curl, CURLOPT_HEADER, FALSE);  // Ask to not return Header
curl_setopt($curl, CURLOPT_COOKIE, "$cookie_session"); // use the previously saved session
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);

And this is what i get as response:

Array
(
    [url] => http://localhost/rests/file
    [content_type] => 
    [http_code] => 500
    [header_size] => 25
    [request_size] => 271
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 8.088799
    [namelookup_time] => 5.5E-5
    [connect_time] => 0.000235
    [pretransfer_time] => 0.000369
    [size_upload] => 1146705
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 141764
    [download_content_length] => 0
    [upload_content_length] => 1146705
    [starttransfer_time] => 0.006217
    [redirect_time] => 0
)

cURL error number:22

cURL error:The requested URL returned error: 500

These are settings from my php that could possibly limiting this:
max_execution_time = 300
max_input_time = 1000
post_max_size = 1G
upload_max_filesize = 1G

Also I am able to upload image larger than 2MB using browser version upload image inside drupal interface .

Do anyone has any idea on any kid of limitation for either rest post content length or services rest server.?

Please advise.

Thanks,
Milorad

Comments

ygerasimov’s picture

Category: bug » support

First, in your code I have found typo:
curl_setopt($curl, CURLOPT_POSTFIELDS, $node_data); // Set POST data

instead of
curl_setopt($curl, CURLOPT_POSTFIELDS, $image_data); // Set POST data

Please take a look at your logs, whether you receive proper arguments for your file create call.

I have tried to upload 2M file locally and it worked (I have substituted simpletest image files with my own big one and ran all tests). So I have difficulties reproducing your problem locally.

mandelic’s picture

Hi,

Thanks for your reply, but i found that i forgot to bump one more limitation.

editing my /etc/my.cnf configuration file for mysql, by setting max_allowed_packet to 50 MB solved problem.

# sets max_packet to 50 MB
max_allowed_packet=50M

Thanks,
Milorad

ygerasimov’s picture

Status: Active » Fixed

Glad that problem is fixed.

Automatically closed -- issue fixed for 2 weeks with no activity.