在Azure的Blob存储

问题描述:

上传和下载图像我试图从使用Azure的PHP SDK中的HTML表单Azure的Blob存储上传图片。当我尝试下载图像时出现问题。结果页面可以在帖子的底部看到。在Azure的Blob存储

我存储使用临时名称的图像,我觉得这是两个问题之一。我不确定,但第二个问题是下载图像时。我必须将它从getContentStream()转换为图像吗?

$ _FILES [ 'driverLicenseFront'] [ 'tmp_name的值']

这是HTML形式上传的图片:

<form role="form" method="POST" action="{path_to_controller}" data-toggle="validator" enctype="multipart/form-data"> 
    <div class="form-group"> 
     <label for="driverLicenseFront">Upload Driver's License(Front)</label> 
     <input type="file" id="driverLicenseFront" name="driverLicenseFront"> 
    </div> 
    <submit button> 
</form> 

在我的文件存储这样的控制器:

// First check if there is a container 
$blob = New Blob($_SESSION['userid']); 
$blob->createContainerIfNotExists(); 
// Upload image to Azure Blob Storage 
$content = fopen($_FILES['driverLicenseFront']['tmp_name'].'', "r"); 
$blob->uploadToContainer($content,'DriverLicenseFrontSide'); 

斑点是我的自定义类来处理斑点

我需要使用链接下载文件:

<a href="../controller/blobs.php?blob_name=DriverLicenseFrontSide" target="_new">Download</a> 

我捕捉到控制器的要求:

if(isset($_GET['blob_name'])){ 
    $blob = New Blob($_SESSION['userid']); 
    $blob->downloadBlob($_GET['blob_name']); 
} 

功能Blob类别:

public function downloadBlob($blob_name){ 
    try { 
     // Get blob. 
     $blob = $this->blobRestProxy->getBlob($this->containerName, $blob_name.'.jpg'); 
     fpassthru($blob->getContentStream()); 
    } 
    catch(ServiceException $e){ 
     // Handle exception based on error codes and messages. 
     // Error codes and messages are here: 
     // http://msdn.microsoft.com/library/azure/dd179439.aspx 
     $code = $e->getCode(); 
     $error_message = $e->getMessage(); 
     echo $code.": ".$error_message."<br />"; 
    } 
} 

结果:

JFIF ,, ICC_PROFILEmntrRGB XYZ $ ACSP - )=ޯUxBʃ9descDybXYZbTRCdmdd gXYZ hgTRC lumi| meas $ bkpt rXYZ rTRC tech已更新 wtptpcprt 7chad ,descsRGB IEC61966-2-1 black scaledXYZ $ curv#( - 27; @ EJOTY^chmrw | ...

+0

嗨Mitsos,必须立即解决您的问题? –

看来,你忘了添加content-type的响应转换二进制内容去形象e内容。

试着在你的downloadBlob()函数中添加以下代码。

$blob = $this->blobRestProxy->getBlob($this->containerName, $blob_name.'.jpg'); 
header("Content-Type:image/jpeg"); 
header('Content-Disposition: attachment; filename="' . $blob_name . '"'); 
fpassthru($blob->getContentStream()); 

任何进一步的问题,请随时让我知道。