0
votes

I am using the Azure PHP SDK to download a blob into a local file. I am using the following code but struggling to produce the actual file on disk. How can indicate where to download the file (folder)?

Is there anything wrong with this code?

Thanks

$blobfile = "123.vox";
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

    $blob = $blobRestProxy->getBlob("containerName", $blobfile);

    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"$blobfile\"");
    fpassthru($blob->getContentStream());
1
I think I should add that this is a PHP scrip running on Linux - IGIT
do you want to just download the file with the PHP script, or this is a PHP page that would send the file to the user browsing your PHP site. Because what you now do is sending the blob to the client. And if you run this PHP script from the console, there is no "client". - astaykov

1 Answers

3
votes

try something like this:

$blobfile = "123.vox";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

$blob = $blobRestProxy->getBlob("containerName", $blobfile);
$source = stream_get_contents($blob->getContentStream());
$localPath = '/var/www/path/to/my/downloaded/file';
$result = file_put_contents($localPath, $source);

HTH,

Susanne