如何通过PHP上传图片到Azure存储?
How to upload an image to Azure storage through PHP?
我正在尝试通过使用 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);
}
(PS。我有 blobClient 的凭据,只是没有在此处包含它以节省不必要的 space。)
我遇到的问题是函数 blobClient->createBlockBlob 采用这些参数...
* @param string $container The name of the container.
* @param string $blob The name of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
所以我遇到的问题是我发送的第三个参数是数组类型,但根据此它应该是字符串。
这是我得到的 PHP 错误...
PHP Fatal error: Uncaught InvalidArgumentException: Invalid resource type: array in D:\home\vendor\guzzlehttp\psr7\src\functions.php:116
如何将图像作为字符串上传到 blob 存储?这里的docs只说明了如何上传文本文件,而不是图片文件。谢谢!
我通过执行以下操作修复了它...
//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);
我正在尝试通过使用 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);
}
(PS。我有 blobClient 的凭据,只是没有在此处包含它以节省不必要的 space。)
我遇到的问题是函数 blobClient->createBlockBlob 采用这些参数...
* @param string $container The name of the container. * @param string $blob The name of the blob. * @param string|resource|StreamInterface $content The content of the blob.
所以我遇到的问题是我发送的第三个参数是数组类型,但根据此它应该是字符串。 这是我得到的 PHP 错误...
PHP Fatal error: Uncaught InvalidArgumentException: Invalid resource type: array in D:\home\vendor\guzzlehttp\psr7\src\functions.php:116
如何将图像作为字符串上传到 blob 存储?这里的docs只说明了如何上传文本文件,而不是图片文件。谢谢!
我通过执行以下操作修复了它...
//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);