Bir MVC5 internet uygulamasını kodluyorum ve bir dosyamı kendi dosya sistemimden bir Azure Blob'a yüklemek için bazı yardımlarda bulunmak istiyorum.Bir dosyayı MVC görünümünden Azure blob depolama alanına nasıl yüklerim?
public void UploadTestFile(string localFileName)
{
string containerName = "TestContainer";
string blockBlogName = "Test.txt";
AzureService azureService = new AzureService();
azureService.UploadFileToBlobStorage(containerName, blockBlogName, localFileName);
}
Ben dan UploadTestFile() işlevi nasıl emin değilim: Burada
public void UploadFileToBlobStorage(string containerName, string blockBlogName, string fileName)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
container.SetPermissions(
new BlobContainerPermissions
{
PublicAccess =
BlobContainerPublicAccessType.Blob
});
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blockBlogName);
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(fileName))
{
blockBlob.UploadFromStream(fileStream);
}
}
bir test dosyası yüklemek için benim fonksiyonudur: Burada
benim Azure kodu yükleme fonksiyonudur MVC Kullanıcının karşıya yüklenecek bir dosyaya götürebileceği görünümü.
Ajax kullanmalı mıyım yoksa bir MVC görünümünden yöntemi çağırarak bir dosya yükleyebilir miyim? Bununla ilgili biraz yardım alabilir miyim? peşin
sayesinde bir MVC Görünümü'nden UploadTestFile() işlevini çağırmak için