2017-09-26 1 views
0

현재 BLOB 내용을 텍스트 문자열로 다운로드하려면 DownloadToStream 메서드를 사용하여 Azure blob 저장소에서 파일을 다운로드하려고합니다. 그러나 나는 아무것도 돌려받지 못하고 있지만 빈 문자열이 있습니다.하늘색 방울 저장소 다운로드 스트림으로 돌아 가기 ""asp.net

하늘빛 얼룩 컨테이너에 연결하고 얼룩 파일을 검색하는 데 사용하는 코드입니다.

public static string DownLoadFroalaImageAsString(string blobStorageName, string companyID) 
    { 
     // 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(companyID.ToLower()); 

     //retrieving the actual filename of the blob 
     string removeString = "BLOB/"; 
     string trimmedString = blobStorageName.Remove(blobStorageName.IndexOf(removeString), removeString.Length); 

     // Retrieve reference to a blob named "trimmedString" 
     CloudBlockBlob blockBlob2 = container.GetBlockBlobReference(trimmedString); 

     string text; 
     using (var memoryStream = new MemoryStream()) 
     { 
      blockBlob2.DownloadToStream(memoryStream); 
      text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()); 
     } 
     return text; 
    } 

나는 this 문서를 따라 갔지만 작동하지는 않습니다. 어떤 도움이라도 대단히 감사하겠습니다.

답변

2

그러나 나는 아무것도 돌려받지 못하고 있지만 빈 문자열입니다.

제공된 코드를 제 측면에서 테스트하면 올바르게 작동합니다. 귀하의 경우테스트 blob 내용이 비어 있다고 가정합니다. 우리는 다음과 같은 방법으로 촬영하는 데 어려움을 겪을 수 있습니다 :

1. memoryStream의 길이를 확인하려고합니다. 길이가 0이면 블롭 내용이 비어 있음을 알 수 있습니다.

using (var memoryStream = new MemoryStream()) 
{ 
    blockBlob2.DownloadToStream(memoryStream); 
    var length = memoryStream.Length; 
    text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()); 
} 

2. 우리는 컨테이너에 대한 내용으로 방울을 업로드 할 수 있습니다, 우리는 푸른 포털 또는 Microsoft Azure storage explorer으로 쉽게 할 수 있습니다. 업로드 된 BLOB로 테스트 해보십시오.

+0

고마워요! blob 저장소 컨테이너에 파일을 업로드하는 방법에 문제가있어서 파일이 존재하지 않아서 내 코드가 아무 것도 반환하지 않는 이유는 무엇입니까? : -S –

+0

@HaydenPassmore 최대 업로드 문제는 다음과 같습니다. 소스 스트림 (재) 위치가 0으로 설정되어 있습니까? 꽤 많은 시간을 내게주었습니다. –

+0

@RickvandenBosch 스트림 위치 감사에 문제가있었습니다. 나는 오늘 일찍 질문을 올렸다. [https://stackoverflow.com/questions/46418526/uploading-file-to-azure-blob-storage-then-sending-http-response-with-the-files-b] –

관련 문제