如何通过PHP将图像上载到Azure存储?

如何通过PHP将图像上载到Azure存储?,php,azure,blob,storage,Php,Azure,Blob,Storage,我正试图通过用PHP构建的API将图像上传到blob存储中 目前我有这个,base64字符串是通过JSON Post发送的 //The base 64 string $displayPictureBase64 = $this->ValidateParameter('DisplayPicture', $this->param, STRING); //Decode it to byte array. $displayPicture[] = base64_decode($displayPi

我正试图通过用PHP构建的API将图像上传到blob存储中

目前我有这个,base64字符串是通过JSON Post发送的

//The base 64 string
$displayPictureBase64 = $this->ValidateParameter('DisplayPicture', $this->param, STRING);
//Decode it to byte array.
$displayPicture[] = base64_decode($displayPictureBase64);
//Name of the blob
$blobName = "MyBlobName";

//New BlobStorage class.
$blob = new BlobStorage;
$blob->AddBlob('user-display-pictures', $blobName, $displayPicture);
这将调用函数AddBlob

public function AddBlob($containerName, $fileName, $fileToUpload)
{
//Upload blob
$this->blobClient->createBlockBlob($containerName, $fileName, $fileToUpload);
}
(顺便说一句,我有blobClient的凭据,只是为了节省不必要的空间而没有在这里包含它。)

我遇到的问题是,函数blobClient->createBlockBlob接受这些参数

所以我的问题是,我发送的第三个参数是array类型的,但根据这一点,它应该是string。 这是我得到的PHP错误

PHP致命错误:未捕获InvalidArgumentException:无效的资源类型:D:\home\vendor\guzzlehttp\psr7\src\functions中的数组。PHP:116


如何将图像作为字符串上载到blob存储?上的仅显示如何上载文本文件,而不是图像文件。谢谢

我通过以下操作修复了它

//The base 64 string
$displayPictureBase64 = $this->ValidateParameter('DisplayPicture', $this->param, STRING);

//Convert the file to stream
$fileToUpload = fopen('data:image/jpeg;base64,' . $displayPictureBase64,'r');
//Name of the blob
$blobName = "MyBlobName";

//New BlobStorage class.
$blob = new BlobStorage;
$blob->AddBlob('user-display-pictures', $blobName, $fileToUpload);
//The base 64 string
$displayPictureBase64 = $this->ValidateParameter('DisplayPicture', $this->param, STRING);

//Convert the file to stream
$fileToUpload = fopen('data:image/jpeg;base64,' . $displayPictureBase64,'r');
//Name of the blob
$blobName = "MyBlobName";

//New BlobStorage class.
$blob = new BlobStorage;
$blob->AddBlob('user-display-pictures', $blobName, $fileToUpload);