0

i am trying to upload an image to imagezilla.net in java. with php using curl it´s no problem..

$pvars   = array('file' => "@".$imagePath, 'apikey' => "apikey");
$timeout = 30;
$curl    = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://imagezilla.net/api.php');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$xml = curl_exec($curl);
curl_close ($curl);
$res = new SimpleXMLElement($xml);

how is it possible to do this in java?

nowkin
  • 25
  • 9

1 Answers1

1

You can use Apache HTTPComponents . It is a bit more complicated than cURL, but, it will do the job (you basically have to fill out a form and POST it).

Dhaivat Pandya
  • 6,499
  • 4
  • 29
  • 43
  • only find examples for uploading file but not with additionell parameters like the apikey i need here – nowkin Jan 28 '13 at 18:45
  • 1
    That's not that difficult. There are examples for adding parameters (google POST form, HTTPComponents) and there are other examples for uploading the files. You simply have to combine the two. – Dhaivat Pandya Jan 28 '13 at 18:46