画像ファイルをblobにアップロードすると、画像は明らかに正常にアップロードされます(エラーはありません)。クラウドストレージスタジオに行くと、ファイルはそこにありますが、サイズは0(ゼロ)バイトです。
以下は私が使用しているコードです:
// These two methods belong to the ContentService class used to upload
// files in the storage.
public void SetContent(HttpPostedFileBase file, string filename, bool overwrite)
{
CloudBlobContainer blobContainer = GetContainer();
var blob = blobContainer.GetBlobReference(filename);
if (file != null)
{
blob.Properties.ContentType = file.ContentType;
blob.UploadFromStream(file.InputStream);
}
else
{
blob.Properties.ContentType = "application/octet-stream";
blob.UploadByteArray(new byte[1]);
}
}
public string UploadFile(HttpPostedFileBase file, string uploadPath)
{
if (file.ContentLength == 0)
{
return null;
}
string filename;
int indexBar = file.FileName.LastIndexOf('\\');
if (indexBar > -1)
{
filename = DateTime.UtcNow.Ticks + file.FileName.Substring(indexBar + 1);
}
else
{
filename = DateTime.UtcNow.Ticks + file.FileName;
}
ContentService.Instance.SetContent(file, Helper.CombinePath(uploadPath, filename), true);
return filename;
}
// The above code is called by this code.
HttpPostedFileBase newFile = Request.Files["newFile"] as HttpPostedFileBase;
ContentService service = new ContentService();
blog.Image = service.UploadFile(newFile, string.Format("{0}{1}", Constants.Paths.BlogImages, blog.RowKey));
画像ファイルがストレージにアップロードされる前は、HttpPostedFileBaseからのプロパティInputStreamは正常であるように見えます(画像のサイズは予想されるサイズに対応しています!例外はスローされません)。
そして、本当に奇妙なことは、これが他の場合(パワーポイントまたはワーカーロールからの他の画像をアップロードする)で完全に機能することです。SetContentメソッドを呼び出すコードはまったく同じであり、ファイルは正しいようです。これは、ゼロバイトの新しいファイルが正しい場所に作成されるためです。
誰か提案がありますか?このコードを何十回もデバッグしましたが、問題がわかりません。どんな提案でも大歓迎です!
ありがとう