Download the Windows Azure Blob Using php

Dec 11, 2013 at 9:16 AM
Hi,

I had uploaded the image as blob in the container, but using below code.

$content = file_get_contents("http://dv.raaga.com/raaga_new/images/hp_slideshow/hp_slide3.jpg", "r");
$blob_name = "slider_img";

try {
//Upload blob
$blobRestProxy->createBlockBlob("raagaimg", $blob_name, $content);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here: 
// http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
How i can download that image

I had used this code, but showing junk code.

My coding is

try {
// Get blob.
$blob = $blobRestProxy->getBlob("raagaimg", "testimg");
fpassthru($blob->getContentStream());
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here: 
// http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
http://dv.raaga.com/raaga_new/windows_azure/download_blob.php

Thanks

Thanigaivelan
Dec 17, 2013 at 9:26 PM
Try it. Works for me.

try {
// Get blob.
$blob = $blobRestProxy->getBlob($your_dir_path, $file_name);
$file = $blob->getContentStream();

header("Content-Type: application/octet-stream"); 
//header("Content-Length:".filesize($file));
header('Content-Disposition: attachment; filename="' . $file_name. '"'); 
header("Content-Transfer-Encoding: binary"); 
header("Expires: 0"); 
header("Pragma: no-cache");

fpassthru($file);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here: 
// http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}