C#でファイルをアップロードするにはどうすればよいですか?私はdialogWindowからファイルをアップロードする必要があります。Blobストレージに単一のファイルをアップロードするAzure
14
A
答えて
2
我々はBackgroundUploaderクラスを使用することができ、その後、我々はStorageFileオブジェクトを提供する必要があるとウリ: 必要な名前空間:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage.Pickers;
using Windows.Storage;
をプロセスは、このようなものです: ウリを使用して定義されますエンドユーザがPickSingleFileAsync操作によって提供されるUIを介してファイルを選択したときに、StorageFileオブジェクトによって表されるアップロードのための所望のファイル
Uri uri = new Uri(serverAddressField.Text.Trim());
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
StorageFile file = await picker.PickSingleFileAsync();
とその後:
BackgroundUploader uploader = new BackgroundUploader();
uploader.SetRequestHeader("Filename", file.Name);
UploadOperation upload = uploader.CreateUpload(uri, file);
// Attach progress and completion handlers.
await HandleUploadAsync(upload, true);
ザッツはすべて
28
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageKey");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
blockBlob.UploadFromStream(fileStream);
}
が必要なSDKおよびリファレンス私は、それはあなたが必要なものだと思う
についてhere参照
1
ここには完全な方法があります。 getconnectionstring方法はこれです
[HttpPost]
public ActionResult Index(Doctor doct, HttpPostedFileBase photo)
{
try
{
if (photo != null && photo.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(photo.FileName);
doct.Image = fileName.ToString();
CloudStorageAccount cloudStorageAccount = DoctorController.GetConnectionString();
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("images");
string imageName = Guid.NewGuid().ToString() + "-" +Path.GetExtension(photo.FileName);
CloudBlockBlob BlockBlob = cloudBlobContainer.GetBlockBlobReference(imageName);
BlockBlob.Properties.ContentType = photo.ContentType;
BlockBlob.UploadFromStreamAsync(photo.InputStream);
string imageFullPath = BlockBlob.Uri.ToString();
var memoryStream = new MemoryStream();
photo.InputStream.CopyTo(memoryStream);
memoryStream.ToArray();
memoryStream.Seek(0, SeekOrigin.Begin);
using (var fs = photo.InputStream)
{
BlockBlob.UploadFromStreamAsync(memoryStream);
}
}
}
catch (Exception ex)
{
}
return View();
}
。
static string accountname = ConfigurationManager.AppSettings["accountName"];
static string key = ConfigurationManager.AppSettings["key"];
public static CloudStorageAccount GetConnectionString()
{
string connectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountname, key);
return CloudStorageAccount.Parse(connectionString);
}
関連する問題
- 1. ファイルをAzure Blobストレージにアップロードする
- 2. Azure Blobがファイルをストレージにアップロードする
- 3. Azure blobストレージのアップロードのパフォーマンス
- 4. 複数のファイルをAzure Blobストレージにアップロードする
- 5. ローカルストレージからAzure BLOBストレージにすべてのファイルをアップロード
- 6. Azure BlobストレージへのFileUploadファイル
- 7. Azure WebJob Powershellスクリプトを使用してAzure Blobストレージにファイルをアップロードする
- 8. AzureのBlobストレージに一時的なBLOBを作成する
- 9. C#Azure "ファイルストレージサービス"にファイルをアップロード - Blobストレージではない
- 10. Azure - 共有ホスティング経由でBLOBストレージにファイルをアップロード
- 11. ファイルをAzure Blobストレージからダウンロードする
- 12. AzureのBLOBストレージからJupyterノートブックにデータをアップロードするには?
- 13. PHP Azureストレージにアップロードした後にBlob URLを取得する
- 14. Windows AzureのWebロールを使用してBlobストレージにファイルをアップロードする
- 15. Azure BlobストレージBLOBを表示する
- 16. Azure Blobストレージのトランザクションアクセス
- 17. Azure BLOBストレージにVHDを並列でアップロードする方法は?
- 18. Azure(.Net)でcsvファイル(既にBLOBストレージにアップロード済み)をインポートする方法
- 19. BlobストレージのAzure Search SDK - ファイルの削除
- 20. Azure Blobストレージのファイル数の制限
- 21. Azure BlobストレージのファイルをAzure SQLデータベースに読み込みます。
- 22. Azure BLOBストレージのあるCNAME
- 23. Azure Blobにファイルをアップロード中のASP.NETコアメモリ
- 24. ローカルファイルシステムにアクセスせずにWebApi経由でAzure Blobストレージにファイルをアップロード
- 25. Azure BLOBストレージをバックアップするには?
- 26. ファイルをAzureファイルストレージからAzure Blobストレージに移動
- 27. Azure BlobストレージからAzure SUSE LINUX VMにファイルをコピー
- 28. アクセスAzure Blobログインユーザーのストレージ
- 29. Azure Blobストレージの代替品
- 30. Azure Blobストレージを持つコンテナのコンテンツを一覧表示する
[Blob transfer utility](https://blobtransferutility.codeplex.com/)の素晴らしいプロジェクトです(すべてC#)。それはあなたにどのように表示されます。 – paqogomez
ここには[GitHub](https://github.com/AgentTy/General.CDN)のC#ラッパーがあり、AzureブロブやAmazon S3で動作し、ローカルキャッシングとバージョンチェックをサポートしています。 –
この[C#Azure Blob Storage Managerクラス](http://cc.davelozinski.com/code/csharp-azure-blob-storage-manager-class)は、誰かがクラスの必要がある場合は、かなり良い基本クラスファイルですC#プロジェクト。 –