Can somebody provide code to save an uploaded file to azure blob in binary? I currently use a text save which is incredibly slow on huge files, reading/saving to blob, line by line.
Private Function ReadFile(ByVal file As HttpPostedFile) As String
Dim result As String = ""
Dim objReader As New System.IO.StreamReader(file.InputStream)
Do While objReader.Peek() <> -1
result = result & objReader.ReadLine() & vbNewLine
Loop
Return result
End Function
Thanks
Click on the ... to the right of the Files box, select one or multiple files to upload from the file system and click Upload to begin uploading the files. To download data, selecting the blob in the corresponding container to download and click Download.
Blob storage is designed for: Serving images or documents directly to a browser. Storing files for distributed access. Streaming video and audio.
You can upload files and directories to Blob storage by using the AzCopy v10 command-line utility.
This code fragment is based on a production app that pushes photos into blob storage. This approach pulls the stream directly from the HttpPostedFile and hands it directly to the client library for storing into a blob. You should vary a few things based on your application:
// assuming HttpPostedFile is in a variable called postedFile
var contentType = postedFile.ContentType;
var streamContents = postedFile.InputStream;
var blobName = postedFile.FileName
var connectionString = CloudConfigurationManager.GetSetting("YOURSTORAGEACCOUNT_CONNECTIONSTRING");
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("YOURCONTAINERNAME");
container.CreateIfNotExist();
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
var blob = container.GetBlobReference(blobName);
blob.Properties.ContentType = contentType;
blob.UploadFromStream(streamContents);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With