Etsy file upload (curl) Err: Request body is too large

512 Views Asked by At

There are few practically the same questions but no good answer. I have to send images to Etsy endpoint.

Decided to use lusitanian library found on git. It internally uses curl to make POST request.

Constantly get "The request body is too large" response.

Code:

$data = [
        //'@image' => new \CURLFile($imagePath, $mime, $imageFilename),
        '@image' => '@'.$imagePath.';type='.$mime,
    ];

    try {
        $response = $etsyService->request(
            $this->uri . '/' . $listingId . '/images',
            'POST',
            $data,
            array(
                'Content-Type'=>'multipart/form-data'
        );
        var_dump($response);die;
    } catch (\Exception $e) {
        var_dump($e->getMessage());
    }

Internally lusitanian uses this:

curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);

to make a request. Tried both from above $data.

Does anybody know how to solve this?

EDIT:

var_dump of header (curl_setopt($ch, CURLINFO_HEADER_OUT, true);)

    array (size=27)
      'url' => string 'https://openapi.etsy.com/v2/listings/645283994/images' (length=53)
      'content_type' => string 'text/plain;charset=UTF-8' (length=24)
      'http_code' => int 400
      'header_size' => int 895
      'request_size' => int 590
      'filetime' => int -1
      'ssl_verify_result' => int 0
      'redirect_count' => int 0
      'total_time' => float 0.234278
      'namelookup_time' => float 3.9E-5
      'connect_time' => float 0.023493
      'pretransfer_time' => float 0.083739
      'size_upload' => float 105
      'size_download' => float 29
      'speed_download' => float 123
      'speed_upload' => float 448
      'download_content_length' => float 29
      'upload_content_length' => float 105
      'starttransfer_time' => float 0.234254
      'redirect_time' => float 0
      'redirect_url' => string '' (length=0)
      'primary_ip' => string '151.101.13.224' (length=14)
      'certinfo' => 
        array (size=0)
          empty
      'primary_port' => int 443
      'local_ip' => string '192.168.2.73' (length=12)
      'local_port' => int 40466
      'request_header' => string 'POST /v2/listings/645283994/images HTTP/1.1

    Host: openapi.etsy.com

    User-Agent: PHPoAuthLib

    Accept: */*

    Authorization: OAuth oauth_consumer_key="**************************", oauth_nonce="****************************8", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1542272124", oauth_version="1.0", oauth_token="*************", oauth_signature="******************"
Content-type: multipart/form-data
Connection: close
Content-Length: 105
1

There are 1 best solutions below

0
On

The problem was (as much as I could see) in the lusitanian library.

In Signature class getSignature method, line 62 stands:

$signatureData[rawurlencode($key)] = rawurlencode($value);

From some reason in this $signatureData are also data from the request body. Because image field is here, which is an object rowurlencode() returned null!

Problem solved (temporary!) with:

if(strpos($key, 'oauth_') !== false) {
    $signatureData[rawurlencode($key)] = rawurlencode($value);
}

And with commented three lines from curlClient class 91 - 93.

It took me a few days to find out. Mr. President give me the medal :)