Question
rzubeldia on Fri, 04 Apr 2014 21:31:21
Hi there, we need to change the contenType in some files already uploaded in Storage
We are working with PHP, anybody can helpme?
Thanks
Replies
Gaurav Mantri on Sat, 05 Apr 2014 02:31:48
The function you would want to call is "setBlobProperties" and just pass the new content type of the blob in "options" parameter. You can look at the source code here: https://github.com/Azure/azure-sdk-for-php/blob/master/WindowsAzure/Blob/BlobRestProxy.php.
Hope this helps.
rzubeldia on Sun, 06 Apr 2014 03:22:04
Gaurav, thanks for reply
I have the next code, and nothing...
$blobName = "010fd745c58c315fd44f6ff6abd730c7.jpg" ;
$blobOption = new CreateBlobOptions();
$blobOption->setBlobContentType("image/jpeg") ;
$ok = $blobRestProxy->setBlobProperties("company", $blobName, $blobOption) ;
echo "Error : " . $ok ."<br />";
Do you have some example to show me?
The apache Log is :
[06-Apr-2014 05:17:56 Europe/Berlin] PHP Fatal error: Call to undefined method WindowsAzure\Blob\Models\CreateBlobOptions::getBlobContentLength() in /Applications/MAMP/htdocs/Kaltin/vendor/microsoft/windowsazure/WindowsAzure/Blob/BlobRestProxy.php on line 1894Gaurav Mantri on Sun, 06 Apr 2014 05:36:48
Try this code:
<?php require_once 'WindowsAzure.php'; use WindowsAzure\Common\ServicesBuilder; use WindowsAzure\Common\ServiceException; use WindowsAzure\Blob\Models\SetBlobPropertiesOptions; try { $containerName = "{containername}"; $blobName = "{blobname}"; $contentType = "{contenttype e.g image/jpg}"; $connectionString = 'DefaultEndpointsProtocol=http;AccountName={accountname};AccountKey={accountkey}'; $queueRestProxy = ServicesBuilder::getInstance()->createQueueService($connectionString); $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); $blobOption = new SetBlobPropertiesOptions(); $blobOption->setBlobContentType($contentType); $ok = $blobRestProxy->setBlobProperties($containerName, $blobName, $blobOption); echo "Error : " . $ok; } catch(ServiceException $e){ $code = $e->getCode(); $error_message = $e->getMessage(); echo $code.": ".$error_message."<br />"; } ?>Hope this helps.