Simple Azure function to get image from storage...
[FunctionName("GetImage")]
public static IActionResult GetImage(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "image/{fileName}")] HttpRequest req,
[Blob("images/{fileName}", FileAccess.Read, Connection = "BlobConnection")] Stream blob,
ILogger log, string fileName)
{
log.LogInformation("Get file from blob " + fileName + " length: " + blob.Length);
MemoryStream ms = new MemoryStream();
blob.CopyTo(ms);
return new FileContentResult(ms.ToArray(), "image/jpeg");
}
Worked just fine, than I faced an issue: can't start azure functions (Internal 500 Error - problem with blob storage).
Additional configuration parameter seems to resolve initialization issue:
"AzureWebJobsSecretStorageType": "files"
Unfortunately now function is not working when executed:
- It logs access with required file name and size.
- It stops for around 25s on blob.CopyTo(ms) line.
- Error:
Executed 'GetImage' (Failed, Duration=26013ms)
System.Private.CoreLib: Exception while executing function: GetImage. Azure.Storage.Blobs: Service request failed.
Status: 500 (Internal Server Error)
Inner source of Exception: Azure.Storage.Blobs.BlobRestClient.Download(...
Any ideas? Thanks in advance.
Connected to Azurite with Microsoft Azure Storage Explorer. No issues there.
Azure Functions Core Tools Core Tools Version: 4.0.4915 Commit hash: N/A (64-bit) Function Runtime Version: 4.14.0.19631
Exception thrown by: blob.CopyTo(ms):
Azure.RequestFailedException: Service request failed.
Status: 500 (Internal Server Error)
Headers:
Server: Azurite-Blob/3.20.1
x-ms-creation-time: Wed, 30 Nov 2022 12:55:17 GMT
ETag: "0x1D64FE85292CAC0"
x-ms-blob-type: BlockBlob
x-ms-lease-state: available
x-ms-lease-status: unlocked
x-ms-client-request-id: 6e6dff50-8c8b-4ccd-bb76-e9b460008293
x-ms-request-id: 91976feb-4421-47a3-9a0e-16a26dc6ad70
x-ms-version: 2021-10-04
Accept-Ranges: bytes
Date: Thu, 15 Dec 2022 08:46:32 GMT
x-ms-server-encrypted: true
x-ms-blob-content-md5: 3KQmtVIakH8iR9D9PlFbSg==
Connection: keep-alive
Keep-Alive: REDACTED
Last-Modified: Wed, 30 Nov 2022 12:55:17 GMT
Content-Length: 18304
Content-Type: image/jpeg
Content-Range: bytes 0-18303/18304
Content-MD5: 3KQmtVIakH8iR9D9PlFbSg==
Content-Disposition:
at Azure.Storage.Blobs.BlobRestClient.Download(String snapshot, String versionId, Nullable1 timeout, String range, String leaseId, Nullable
1 rangeGetContentMD5, Nullable1 rangeGetContentCRC64, String encryptionKey, String encryptionKeySha256, Nullable
1 encryptionAlgorithm, Nullable1 ifModifiedSince, Nullable
1 ifUnmodifiedSince, String ifMatch, String ifNoneMatch, String ifTags, CancellationToken cancellationToken)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.StartDownloadAsync(HttpRange range, BlobRequestConditions conditions, Boolean rangeGetContentHash, Int64 startOffset, Boolean async, CancellationToken cancellationToken)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.DownloadStreamingInternal(HttpRange range, BlobRequestConditions conditions, Boolean rangeGetContentHash, IProgress`1 progressHandler, String operationName, Boolean async, CancellationToken cancellationToken)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<>c__DisplayClass92_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Azure.Storage.LazyLoadingReadOnlyStream1.DownloadInternal(Boolean async, CancellationToken cancellationToken) at Azure.Storage.LazyLoadingReadOnlyStream
1.ReadInternal(Byte[] buffer, Int32 offset, Int32 count, Boolean async, CancellationToken cancellationToken)
at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](Task1 task) at Azure.Storage.LazyLoadingReadOnlyStream
1.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
at System.IO.Stream.CopyTo(Stream destination)
at StandardFunctions.BloobFunctions.GetImage(HttpRequest req, Stream blob, ILogger log, String fileName) in C:\Dev\StandardFunctions\BloobFunctions.cs:line 39
Fresh installation of OS and VS. The same code with the same configuration is working just fine :/