2017-11-23 8 views
1

Der folgende Code schlägt fehl bei: bodycreader.ReadToEnd() Ich möchte große Dateien von DROPBPOX herunterladen, ohne es in meinem Speicher/Localdisk zu speichern. Ich verwende Parallel.Forloop, um mehrere Dateien herunterzuladen.Lesevorgang fehlgeschlagen. Large Files Azure BlobUpload mit nur Stream von DROPBOX api

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) 
      { 

      } 

dann haben wir versucht, ohne Blöcke UploadFromStream nur

Gefällt Ihnen dieses

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

Damit für kleine Dateien, die es erfolgreich & für große Dateien bis zu 50% der Datei hochzuladen es später wird das Hochladen wir bekommen Ausnahme wie

Anfrage wurde abgebrochen Anfrage wurde

abgesagt

Antwort

0

Der folgende Code nicht an: bodyreader.ReadToEnd() Ich große Dateien von DROPBPOX herunterladen möchten, ohne es in meinem Gedächtnis/Localdisk zu speichern.

Für vorübergehend große Datei auf der lokalen Festplatte zu speichern, Sie diese ähnliche issue folgen könnte, dann könnte man CloudBlockBlob.UploadFromFile verwenden und die BlobRequestOptions angeben, dann würde der Client-SDK große Datei in Blöcke brechen und automatisch bei jedem Block parallel laden für Sie. Sie können diesem issue folgen und dieses blog über hochladen eine Datei mit dem .NET Storage SDK.

Für große Datei in den Speicher vorübergehend zu speichern, ging ich davon aus, dass Sie BlobRequestOptions Parameter für UploadFromStream Methode angeben könnten versuchen, und die Begrenzung erhöhen (z BlobRequestOptions.ParallelOperationThreadCount, BlobRequestOptions.ServerTimeout, etc.) Um dieses Problem zu verengen.

Verwandte Themen