Deflate gzip'ed blob when copying it to Azure file share - c#

I have a SAS uri from a blob containing Content-Encoding set to gzip and Content-Disposition set to rename the downloaded file. This works fine when accessing the link through the browser. What I want to achieve however is copy the file over to an Azure File share (StartCopyAsync) using the said blob SAS uri. This works, but the end result on the file share isn't decompressed like when downloaded through the browser.
Any ideas how this can be achieved?

Copy operation will not automatically decompress the content for you. It will simply copy the raw data and properties from source blob to destination file.
If you want to have the decompressed content in file storage, you will have to write the code to do that. You would need to write the code to download the blob, decompress its contents and then upload the decompressed content in file storage.

Related

Convert pdf file to blob c#

I have a created a file in my service (E:\User\example.pdf) and I want to convert that to blob in my controller to download the file using axios in my front-end.
How to do that? Thanks
As previous stated, won't hurt to check more on BLOB : https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction
Here is how to UPLOAD FILE TO BLOB: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet#upload-blobs-to-a-container

Azure Blob Storage BlockBob - Replaced File Not Shown

I am using Azure blob storage in my project.And when I am trying to update an existing file, if the new file name is different from the current file name it will be updated and shown through the url. But the case is if the new file has a different name from the current file name, yes it will be updated but it will not be shown through the url. When I meant through the URL it means through the browser. And it is not being cached by the browser. I tried clearing browser cached and even used a different browser.
The URL is - https://cubictechdemo.blob.core.windows.net/media/Cache%202017_12062017111606.pdf
But still if I passed a query like https://cubictechdemo.blob.core.windows.net/media/Cache%202017_12062017111606.pdf?xxx
it will give me the updated file.
And however it would be downloaded through blockBlob.DownloadToStream() method. The url shows the old file and the downloadToStream gives me the updated file.
I don't know why this is happening. I am using UploadFromStream method. I can only get the new file if i passed some query.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(fileInput);
blockBlob.FetchAttributes();
Does anybody know why that is? Thank You.

Copy or Download an image file from URI to Azure Blob

I have an image uri: https://api.tinify.com/output/im1c1s69phhvjjm6.jpg
This is a result image coming from an online image minification api.
And I wanted to download the minified image to a blob container in Azure.
I did:
var newBlockBlob = container.GetBlockBlobReference("minified-sample.jpg");
newBlockBlob.StartCopy(new Uri(fileUrl), null, null, null);
What happens then is that all I see is a 0 byte image file in the container.
I think there's an issue with the headers in the image you're trying to copy. I believe Content-Disposition header is set for this image. The reason I say this is because when I paste the URL in browser's address bar, instead of displaying the image in the browser I get prompted to download the image.
For copy operation to work, the Blob Service must be able to read the contents of the remote file in response stream when it requests the URL. Because the URL request results in downloading the file, Blob Service is not able to read the contents of the file and thus you get a 0 byte blob.
Edit: This is what I see in Google Postman

allowing users to download files from azure blob storage as single zip file

I have multipl files in my blob storage. Also I have a azure database table which stores url which points to actual individual files in blob storage .
On my webform user can specify search criteria.Then it will search for files that match the search condition and show a single link to download matching files all as a single zip file.
I have my search results returned as a list. for example
List searchresults
This search result will contain multiple urls
eg.,searchresults.url ="https://myblobstorage.blob.windows.net\xyz\mymusic.mp3"
if there are matching records ,it will show a single download link on the page,so that the user can click on the link and download the the matching files together as as single zip file.
I am able generate the searchresultsList with the required file urls pointing to the files in my azure blob container.
Now my Question
Is there a way I can generate a zip file by looping through the searchresultsList and grabbing files from blob and generate a single zip file for the user to download them? Give me your suggestions or some sample code to achieve this functionality.
When the user clicks on the link, it should go and fetch all the files from corresponding urls from the search results list and generate a single zip file and download to the users machine
You need to download the blobs to your server, generat a zip and push that to the client.
You can use the following lib to generate the zip file http://dotnetzip.codeplex.com/
The blobs you can download to the client via the .NET SDK provided with the Azure framework. It should be a simple solution, really.

Displaying BLOB data in a Browser

I need to display my BLOB data directly into the IE Browser without saving a temporary file on the hard Disk.
I have successfully implemented the method of retrieving the file from the blob.
Please help me out or direct me to good articles on how to acheive this functionality.
Im using Visual Studio 2005, C#.NET and Oracle
You could do the following in an HTTP handler :
context.Response.ContentType = "multipart/related"; // I think...
context.Response.Write(<blob data here>);
Now this relies on a browser - IE, firefox - that can handle mht files..
If you want to parse the mht file and return html etc.. that would be a whole different scenario!
If you've already code that saves it as a file then all you need to do is to change that to write it to the Response.OutputStream stream instead of the file stream.

Categories

Resources