2017-11-23 4 views
1

bodyreader.ReadToEnd() 대용량 파일을 내 메모리/localdisk에 저장하지 않고 DROPBPOX에서 다운로드하고 싶습니다. Parallel.Forloop을 사용하여 여러 파일을 다운로드하고 있습니다.읽기 작업이 실패했습니다. 대용량 파일 DROPBOX API 스트림 만 사용하는 Azure BlobUpload

public static DropboxClient dropboxClient; 
    var response = await dropboxClient.Files.DownloadAsync(file[0]); 
    var fileStream = await response.GetContentAsStreamAsync(); 

try { 
       container = obj.BloBHandle(); 
       table = obj.TableHandle(); 
       StreamReader bodyReader = new StreamReader(filepath); 
       string bodyString = bodyReader.ReadToEnd(); 

       block = container.GetBlockBlobReference(filename); 

       int blockSize = 4 * 1024 * 1024; //256 kb 
       int fileSize = bodyString.Length; 
       //long fileSize = filepath.Length; 


       //block count is the number of blocks + 1 for the last one 
      int blockCount = (int)((float)fileSize/(float)blockSize) + 1; 

      //List of block ids; the blocks will be committed in the order of this list 
      List<string> blockIDs = new List<string>(); 
      //starting block number - 1 
      int blockNumber = 0; 

       int bytesRead = 0; //number of bytes read so far 

       long bytesLeft = fileSize; //number of bytes left to read and upload 

       //do until all of the bytes are uploaded 
       while (bytesLeft > 0) 
       { 
        blockNumber++; 
        int bytesToRead; 
        if (bytesLeft >= blockSize) 
        { 
         //more than one block left, so put up another whole block 
         bytesToRead = blockSize; 
        } 
        else 
        { 
         //less than one block left, read the rest of it 
         bytesToRead = (int)bytesLeft; 
        } 

        //create a blockID from the block number, add it to the block ID list 
        //the block ID is a base64 string 
        string blockId = 
         Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("BlockId{0}", 
         blockNumber.ToString("0000000")))); 
        blockIDs.Add(blockId); 
        //set up new buffer with the right size, and read that many bytes into it 
        byte[] bytes = new byte[bytesToRead]; 
        filepath.Read(bytes, 0, bytesToRead); 
        // Stream stream = new MemoryStream(bytesToRead); 

        //calculate the MD5 hash of the byte array 
        string blockHash = GetMD5HashFromStream(bytes); 

        //upload the block, provide the hash so Azure can verify it 
        block.PutBlock(blockId, new MemoryStream(bytes), blockHash); 

        //increment/decrement counters 
        bytesRead += bytesToRead; 
        bytesLeft -= bytesToRead; 
       } 

       //commit the blocks 
       block.PutBlockList(blockIDs); 



      } 
      catch (Exception ex) 
      { 

      } 

는 우리는 그냥 나중에 업로드되는 파일의 50 %를 최대 개까지 큰 파일을 성공적으로 & 업로드되는 작은 파일이 사항은이

block = container.GetBlockBlobReference(filename);  
    block.UploadFromStream(stream); 

처럼

을 UploadFromStream 블록하지 않고 시도

요청이 중단되었습니다. 내 메모리/localdisk에 저장하지 않고 DROPBPOX에서 큰 파일을 다운로드하려면() bodyreader.ReadToEnd : 아래의 코드에 실패

답변

0

을 취소했습니다.

일시적으로 로컬 디스크에 큰 파일을 저장하기 위해, 당신이 유사한 issue에 따라 수, 당신은 CloudBlockBlob.UploadFromFile을 사용하고 BlobRequestOptions를 지정한 다음 클라이언트 SDK가 블록으로 큰 파일을 끊을 자동으로 병렬로 각 블록을 업로드 할 수 당신. issue 및이 blog을 사용할 수 있습니다. .NET 저장소 SDK을 사용하여 파일 업로드.

일시적으로 메모리에 대용량 파일을 저장, 나는 당신이 (예를 들어 BlobRequestOptions.ParallelOperationThreadCount, BlobRequestOptions.ServerTimeout 등이.)이 문제를 좁힐 수 제한을 UploadFromStream 방법에 대한 BlobRequestOptions 매개 변수를 지정하고 향상을 시도 할 수 있다고 가정한다.

관련 문제