이미지 파일을 BLOB에 업로드하면 이미지가 분명히 성공적으로 업로드됩니다 (오류 없음). 클라우드 스토리지 스튜디오에 갈 때 파일은 있지만 크기는 0 (제로) 바이트입니다.하늘빛 저장소 : 크기가 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 메서드를 호출하는 코드는 정확히 같고 0 바이트의 새 파일이 올바른 위치에 만들어 지므로 파일이 올바른 것 같습니다.
아무도 제안을 해주지 않습니까? 이 코드를 수십 번 디버깅했는데 문제가 보이지 않습니다. 어떤 제안이라도 환영합니다!
감사
이 약간 명확히하기 위해, 당신은로드 후 0으로 스트림의 위치 속성을 설정해야합니다 확인 그것으로 어떤 바이트 든. 기본적으로 스트림의 위치는 어떤 이유로 든 콘텐츠의 끝으로 설정됩니다. – Dusda
네, 그건 제가 항상 알고있는 것입니다. 그리고 나는 그것을 기억하기 위해 1 초 이상을 결코 풀어 내지 못합니다. 감사! –
고마워요 :) –