How can I send an imagic-image with http post without writing image to a disk? The code below isn't working.
// function returns an Imagick Object
$image = $this->generateLvlImage($avatarUrl, $lvl);
// I want to send it with http post
$postRequest = new \HttpRequest($uploadUrl, \HttpRequest::METH_POST);
$postRequest->addRawPostData('photo='.(string)$image);
try {
$postRequest->send();
if ($postRequest->getResponseCode() === 200) {
$response = $postRequest->getResponseBody();
} else {
throw new \Exception('post.failed');
}
} catch (\HttpException $e) {
throw new \Exception($e->getMessage());
}
It's really hard to say for sure without knowing exactly who/what you're attempting to submit it to. Typically, you would base64_encode the image and then base64_decode it on the other end.
$postRequest->addRawPostData('photo='.base64_encode($image->getImageBlob()));
Edit: If you want to send it via multi-part form data then I couldn't give you an answer without plagiarising someoneelses work, so here is a tutorial on it: http://blog.cloudspokes.com/2013/01/reblog-post-multipartform-data-with.html