2013-08-09 2 views
1

참고 : Azure 블롭 스토리지로 전송해야하는 예제 SAS 문자열 (오른쪽 영역에 블록 정보가 추가됨)을 누군가에게 줄 수 있습니까? 나는 그것이 내가 가지고있는 문제라고 생각한다. 각 블록과 함께 Azure로 전송되는 문자열에 uri, key 등의 순서를 알아야합니다.두 번째 청크에서 REST API를 사용하여 블록에 블롭 업로드하기

내가 달성하고자하는 것은 서비스에서 SAS 키를 가져 와서 문자열 키를 수정하여 하늘이 내가 블록으로 전송한다는 것을 알게 한 다음 sas 키를 사용하여 파일의 개별 블록을 보냅니다. 웹 클라이언트에서. 나는 각 파일을 2MB 블록 단위로 청취하고 있으며, 한 번에 2MB 블록을 자바 스크립트 라이브러리와 함께 보내고있다. 따라서 아래 코드의 각 "파일"은 단지 파일의 2MB 청크입니다.

문제 : 서비스에서 SAS 키를 가져 와서 블록 덩어리 정보를 포함하도록 키를 수정하고 FIRST 덩어리를 보내고 Blob 스토리지 서버에서 응답을받을 수 있습니다. 그러나 두 번째 청크를 보내면 BLOB 저장소에 대한 스트림 요청이 중지 된 다음 결국 시간이 초과됩니다. 타임 아웃은 blob 저장소에 대한 스트림에 대한 두 번째 요청에서 특히 발생하는 것으로 보입니다. 여기 코드의이 비트 :

서버에 웹 클라이언트 코드 :

using (Stream requestStream = request.GetRequestStream()) 
    { 
     inputStream.CopyTo(requestStream, file.ContentLength); 
    } 

시간에 두 번째 덩어리를 일으키는 원인이 무엇이 될 수 있을까? 열쇠 창문이 너무 빨리 닫힐 수 있습니까? 웹 서버 클라이언트에 덩어리를 전송

private void WriteToBlob(HttpPostedFileBase file, string BlockId, FileProp fp) 
    { 
     var inputStream = file.InputStream; 

     Microsoft.WindowsAzure.StorageCredentialsSharedAccessSignature credentials = 
      new Microsoft.WindowsAzure.StorageCredentialsSharedAccessSignature(fp.facct); 


     string queryString = (new Uri(fp.folderName)).Query; 

     string RequestUri = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}{2}&comp=block&blockid={3}", 
      fp.folderName, fp.fileName, queryString, Convert.ToBase64String(Encoding.UTF8.GetBytes(BlockId))); 

     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(RequestUri); 
     request.Method = "PUT"; 
     request.ContentLength = inputStream.Length; 
     using (Stream requestStream = request.GetRequestStream()) 
     { 
      inputStream.CopyTo(requestStream, file.ContentLength); 
     } 

    } 

자바 스크립트 코드 :

 var running = 0; 
    var chunksize = (Modernizr.blobconstructor) ? uploadChunkSize : null; //if browser support Blob API 
    window.xhrPool = []; 
    $('#fileupload').fileupload({ 
     url: url, 
     //formData: [{ name: 'param1', value: 1 }, { name: 'param2', value: 2}], 
     singleFileUploads: true, //each file is using an individual XHR request 
     //limitMultiFileUploads: 2, //This option is ignored, if singleFileUploads is set to true. 
     multipart: true, 
     maxChunkSize: chunksize, //server side is in streaming mode 
     sequentialUploads: true, //Set this option to true to issue all file upload requests in a sequential order instead of simultaneous requests. 
     dataType: 'json', 
     autoUpload: true, 
     //acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 
     progressInterval: 100, 
     bitrateInterval: 100, 
     maxFileSize: uploadFileSizeLimit 
    }).on('fileuploadadd', function (e, data) { 

     var filename = data.files[0].name; 
     var filesize = data.files[0].size; 
     if (filesize == 0) { 
      var zeroSizeErrMsg = sceneLayoutService.format('This file {filename} is empty please select files again without it. ', { filename: filename }); 
      sceneLayoutService.showErrorDialog(zeroSizeErrMsg); 
      return; 
     } 

     if (window.availableStorageSize != null && window.availableStorageSize != '') { 
      if (filesize > window.availableStorageSize) { 
       var overSizeErrMsg = sceneLayoutService.format('File size of {filename} exceeds available storage space in your cloud drive. ', { filename: filename }); 
       sceneLayoutService.showErrorDialog(overSizeErrMsg); 
       return; 
      } 
     } else { 
      alert('Unable to retrieve the storage usage.'); 
     } 

     data.jqXHR = data.submit(); 
     window.xhrPool.push(data.jqXHR); 
     sceneLayoutService.addFileToProgressDialog(data, cancelButton); 

    }).on('fileuploadprocessalways', function (e, data) { 

    }).on('fileuploadprogressall', function (e, data) { 

    }).on('fileuploadsubmit', function (e, data) { 

     var filesize = data.files[0].size; 
     if (filesize == 0) { 
      return false; 
     } 

     if (window.availableStorageSize != null && window.availableStorageSize != '') { 
      if (filesize > window.availableStorageSize) { 
       return false; 
      } 
     } 
     $('#dlgProgress').parent().show(); 
     running++; 
     sceneLayoutService.showProgressDialog('Uploading files to ' + currentUser + '\'s Cloud Storage ...', abortAllUploads); 
     return true; 

    }).on('fileuploaddone', function (e, data) { 

     running--; 
     updateStorageQuota(function() { 
      var usedStorageSize = (window.usedStorageSize != null) ? bytesToSize(window.usedStorageSize, 2) : 0; 
      var totalStorageSize = (window.totalStorageSize != null) ? bytesToSize(window.totalStorageSize, 2) : 0; 
      var usageFooterStr = sceneLayoutService.format("Using {used} of {total} (%)", { used: usedStorageSize, total: totalStorageSize }); 
      $('div.dlgProgressFooter').text(usageFooterStr); 
     }); 


     var docGridUrl = window.baseUrl + '/CloudStorage/ChangePage?page=1&rand=' + sceneLayoutService.getRandomString(4); 
     $('#docGridPartial').load(docGridUrl, function() { 
      grid.init({ 
       pageNumber: 1, 
       url: window.baseUrl + '/CloudStorage/ChangePage', 
       sortColumn: '', 
       sortDirection: '' 
      }); 
     }); 

     sceneLayoutService.updateFileUploadFinalStatus(data, 'done'); 

     if (!data.result.success) { 
      debugger; 
      var errMsg = ""; 
      if (data.result != null) { 
       if (data.result.message != null) { 
        errMsg += data.result.message; 
       } 
       if (data.result.error != null) 
        errMsg += data.result.error; 
      } 
      sceneLayoutService.showErrorDialog(errMsg); 
     } 
     window.removeXHRfromPool(data); 

     if (running == 0) { 
      $('#dlgProgress').parent().hide(); 
      $('#progresses').empty(); 
     } 
    }).on('fileuploadfail', function (e, data) { 
     running--; 

     sceneLayoutService.updateFileUploadFinalStatus(data, 'fail'); 

     window.removeXHRfromPool(data); 

     if (running == 0) { 
      $('#dlgProgress').parent().hide(); 
      $('#progresses').empty(); 
     } 
    }).on('fileuploadprogress', function (e, data) { 

     //XHR upload onProgress event not fired at server-defined intervals/not supported in IE8 and IE9, 
     //will be supported in IE10 in terms of XMLHttpRequest Level 2 specification, http://caniuse.com/xhr2 
     sceneLayoutService.updateFileUploadProgress(data); 
    }); 

enter image description here

enter image description here

+0

빠른 질문 - 각 게시 된 파일이 별도의 블록으로 업로드된다는 사실을 이해 했습니까? 오류와 관련이 없지만 블록 ID를 일반 문자열로 전달하는 것으로 나타났습니다. Base64로 인코딩 된 문자열로 변환 한 다음 URL로 전달해야합니다. –

+0

저는 각 파일을 2MB 블록 단위로 묶어서 한 번에 2MB 블록을 자바 스크립트 라이브러리와 함께 보냅니다. 따라서 위의 코드에서 각 "파일"은 단지 파일의 2MB 청크입니다. BlockId에 대해서는 원래 Base64 : Convert.ToBase64String (Encoding.UTF8.GetBytes (BlockId))으로 설정했습니다. 난 그냥 변환하지 않고 노력했지만 여전히 같은 문제로 실행. – TheDude

+0

설명해 주셔서 감사합니다. JavaScript로 클라이언트 측에서 파일을 청크하기위한 코드를 공유 할 수 있습니까? HTML 5의 File API를 사용하고 있습니까? 나는 내 문제를 재현하려고 노력할 것이다. –

답변

1

문제 해결 다음은 내 코드와 스크린 샷입니다. SAS URI 형식이 잘못되었습니다. 다음은 Sas URI (컨테이너의 경우)의 모습입니다.

http://container_uri/filename?key 
관련 문제