I am making an API call that should return a list of PNGs . I'm storing the PNG in blob storage and I'm able to successfully grab them. In the past when I've only had to return one image, I'd convert the blob to a memory stream and just handle the memory stream on the client side. That does not seem to work for multiple files though.
[HttpGet("getThumbnails/{seriesId}")]
public async Task<ActionResult<List<MemoryStream>>> GetThumbnails(string seriesId)
{
var pngs = await _service.LoadPNGsMs(seriesId);
Response.ContentType = "image/png ";
return pngs;
}
public async Task<List<MemoryStream>> LoadPNGsMs(string seriesID)
{
var returnList = new List<MemoryStream>();
var blobls = await _azureBlobStorageService.GetBlockBlob(seriesID);
foreach (var blob in blobls)
{
var stream = new MemoryStream();
await blob.DownloadToStreamAsync(stream);
stream.Position = 0;
returnList.Add(stream);
}
return returnList;
}
public async Task<List<CloudBlockBlob>> GetBlockBlob(string seriesID)
{
var blobFiles = containerClient.GetBlobs(prefix: seriesID);
var blobFilePaths = blobFiles.Select(x => x.Name).ToList();
List<CloudBlockBlob> cloudBlockBlobs = new List<CloudBlockBlob>();
foreach (var blob in blobFilePaths)
{
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(blob);
bool isExists = await blockBlob.ExistsAsync();
if (isExists)
cloudBlockBlobs.Add(blockBlob);
}
return cloudBlockBlobs;
}
I am getting a 406 for running this code. Am I doing too much setting the response type to be image/png
? Should I just work with the blobs and forget about the memory streams? I'll keep playing around with this here and post results if I find anything.