I am using the following code to upload an image to an existing listing in PHP. The image is present in the same directory where the code is.
<?php
ini_set('display_errors',true);
define('OAUTH_CONSUMER_KEY', '<MY-KEY>');
define('OAUTH_CONSUMER_SECRET', '<MY-SECRET>');
$listing_id="242953861";
$listing_image_id = "";
$filename="abc.jpg";
$access_token="<ACCESS-TOKEN-HERE>";
$access_token_secret="<TOKEN-SECRET-HERE>";
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
$oauth->setVersion("1.1");
$oauth->enableDebug();
$oauth->setToken($access_token, $access_token_secret);
try {
$source_file = dirname(realpath(__FILE__)) ."/$filename";
$mimetype=mime_content_type($source_file);
$filesize=filesize($source_file);
$params = array('@image' => '@'.$source_file.';type='.$mimetype);
$header["Content-Type"] = 'multipart/form-data';
$header["Content-Length"] = $filesize;
$data=$oauth->fetch($url, $params, OAUTH_HTTP_METHOD_POST,$header);
$json = $oauth->getLastResponse();
print_r(json_decode($json, true));
} catch (OAuthException $e) {
echo "<pre>";
print $oauth->getLastResponse()."\n";
print_r($oauth->debugInfo);
die($e->getMessage());
}
The Code is same as mentioned in Etsy Developer Documentation and the URL is here :
But I could not able to upload the image, its showing errors as follows. I have spent so many hours searching in the web but could not find any suitable article.
Please some one help me finding the issue.
Image file or image_id string must be included
Array
(
[sbs] => POST&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Flistings%2F242953861%2Fimages........
[headers_sent] => Content-Type: multipart/form-data
[headers_recv] => HTTP/1.1 400 Bad Request
Server: Apache
Set-Cookie: uaid=uaid%3DTBxjj5JIeT8AiD5HbLU-oSYKGyUq%26_now%3D1439043021%26_slt%3DABLJqdpZ%26_kid%3D1%26_ver%3D1%26_mac%3Dp9Piw9YybzhknMXmDFh683M0E93IiFcm23-FIUUEXj4.; expires=Wed, 07-Sep-2016 06:28:41 GMT; Max-Age=34186700; path=/; domain=.etsy.com; httponly
X-Etsy-Request-Uuid: _sDEiCigwVAujsOWBCgt09p53rvH
X-RateLimit-Limit: 10000
X-RateLimit-Remaining: 9873
X-Error-Detail: Image file or image_id string must be included
Cache-Control: private
X-Cnection: close
Content-Type: text/plain;charset=UTF-8
Content-Length: 46
Accept-Ranges: bytes
Date: Sat, 08 Aug 2015 14:10:21 GMT
Via: 1.1 varnish
Connection: close
X-Served-By: cache-fra1239-FRA
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1439043021.363271,VS0,VE138
[body_recv] => Image file or image_id string must be included
)
Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)