use*_*821 8 binary blob file-upload azure
有人可以提供代码将上传的文件保存到二进制文件中的azure blob吗?我目前使用文本保存,这对于大文件来说非常慢,读取/保存到blob,逐行.
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
Run Code Online (Sandbox Code Playgroud)
谢谢
此代码片段基于将照片推送到blob存储的生产应用程序.这种方法直接从HttpPostedFile中提取流,并将其直接交给客户端库以存储到blob中.你应该根据你的应用程序改变一些东西:
// 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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2940 次 |
| 最近记录: |