私のプロジェクトでは、ファイルをアップロードする必要があります。これをBlobストレージに送信します。現在、既に保存されているファイルのみを送信できます。ユーザーがアップロードしたファイルを送信する必要があります。ここでAzure Blobがファイルをストレージにアップロードする
しかし、私は(VARのFILESTREAM = System.IO.File.OpenRead(ファイル))を使用して
を変更する方法がわからないです、ファイルをアップロードするために私の現在のコードです
それで、 "HttpPostedFileファイル"からファイルを取得します
コードのコメントアウトされた部分は、クラウドではなく私のシステムに保存された古いバージョンです。
// POST: DocumentUps/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateUpload([Bind(Include = "DocumentId,DocName,creationDate,RevisionNumber,Author,Status,ActivationDate,Attachment,RevisionId")] DocumentUps documentUps, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
documentUps.RevisionId = documentUps.DocumentId;
documentUps.Username = User.Identity.Name;
documentUps.Attachment = file.FileName;
documentUps.creationDate = DateTime.Now;
documentUps.ActivationDate = DateTime.Now;
documentUps.RevisionNumber = 0;
documentUps.Status = StatusChoice.Draft;
db.DocumentUps.Add(documentUps);
db.SaveChanges();
int id = documentUps.DocumentId;
DocumentUps docsup = db.DocumentUps.Find(id);
documentUps.RevisionId = id;
documentUps.Username = User.Identity.Name;
documentUps.Attachment = documentUps.Attachment;
documentUps.DocumentId = documentUps.DocumentId;
documentUps.creationDate = documentUps.creationDate;
documentUps.ActivationDate = DateTime.Now;
documentUps.RevisionNumber = 0;
documentUps.DocName = documentUps.DocName;
documentUps.Author = documentUps.Author;
documentUps.Status = StatusChoice.Draft;
db.Entry(documentUps).State = EntityState.Modified;
db.SaveChanges();
if (file != null && file.ContentLength > 0)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("filestorageideagen_AzureStorageConnectionString"));
Microsoft.WindowsAzure.StorageClient.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
Microsoft.WindowsAzure.StorageClient.CloudBlobContainer container = blobClient.GetContainerReference("documentuploader");
Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blob = container.GetBlockBlobReference("TestUpload");
using (var fileStream = System.IO.File.OpenRead(file))
{
blob.UploadFromStream(fileStream);
}
//var fileName = documentUps.DocumentId.ToString() + documentUps.RevisionId.ToString() + Path.GetFileName(file.FileName);
//var path = Path.Combine(Server.MapPath("~/Content/fileHistory"), fileName);
//file.SaveAs(path);
}
あなたは 'HttpPostedFile'の' InputStream'を読もうとしませんでしたか? https://msdn.microsoft.com/en-us/library/system.web.httppostedfile.inputstream(v=vs.110).aspx –