• 0
vittorio

[PHP ]Uploading images from hard drive

Question

Hi! i 'm trying to post an item with pictures. I'm able to do so if i use public images that are hosted in some web pages 

Is it possible to use images from your own hard drive? without uploading them to a server?

This is my code:

$params = array('access_token' => $_SESSION['access_token']);

$body = array("price" => '2',
              "title" => 'LOCAL 2ND TRIAL',
              "category_id"=> 'MLA40490',
              "currency_id"=>"ARS",
              "available_quantity"=>1,
              "condition"=>"used",
              "listing_type_id"=>"silver",
              "pictures"=>array(array("source"=>"C:\xampp\htdocs\logoHgin.jpeg"))
              );

$response = $meli->post('/items', $body, $params); 

It works perfectly if i replace the image url by a public one. The problem is i have hundreds of pics that i dont want to upload to a public server (it defeats the purpose of the app i'm writing).

Is it possible to upload images directly from the hard drive??

Thanks in advance!!

 

 

 

 

 

 

Edited by vittorio

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Thanks for your answer juvian!

The problem is, I had already tried that, but the picture never shows. All i see is the "processing image"  default image.

The picture gets uploaded to the mercadolibre server (supposedly), since i get a 201 code when I examine the response. I also get the uploaded picture id and i'm able to retrieve the uploaded picture from the api. But there´s no way to see the picture. However if I use a picture already uploaded to certain public servers, the picture is visible inmeadiately. Last night I uploaded a picture directly from my hard drive using the code you mentioned and this morning still was "in process" so I take it that means it will never get uploaded. (I can´t wait 12 hours to upload a photo.)

Here´s my code:

//upload an image from the local hard drive to the mercadolibre server:

 $body2=array("source"=>"C:\xampp\htdocs\hgin\php-sdk-master\examples\logoHgin.jpg");

$response2 = $meli->post('/pictures', $body2, $params);

//associate the recently uploaded picture to a previously created post

$body3=array("id"=>"897268-MLA26367623449_112017", "max_size"=>"100*100");

$response3 = $meli->post('/items/MLA692059690/pictures', $body3, $params);

Please note the part in bold, i'm using a file path, not an url because i'm trying to upload the pictures directly from the hard drive.

Like i said i 'm able to do so, or at least both requests have a 201 response. But the picture never shows.

Juvian, could you walk me through  what I'm doing wrong? I need to upload the pictures directly from the hard drive.

A million thanks in advance!!

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites
  • 0

Well, clearly ml has no way to access your internal file image just from your computer path. You need to upload the image binary data, in a special format. There is not much documentation about it, you can either try the curl example they give in their docs and then set curl debugging options to check how is curl sending the data, or you can just search how file upload is done in general: https://stackoverflow.com/questions/21905942/posting-raw-image-data-as-multipart-form-data-in-curl.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now