2011-12-29 7 views
5

azure blobストレージにファイルを直接アップロードしようとすると問題が発生します。私はチャンクにBLOBをアップロードするために、ashxハンドラにポストリクエストを送るためにajaxコールを使用しています。私が実行している問題は、ハンドラがajax投稿から送信されたファイルチャンクを受信して​​いないことです。Azureにアップロード

私は、ページが放火犯でリクエストを見てから正しくポストを受信して​​いる

を見ることができます---------------------- ------- 265001916915724コンテンツの処理:フォームデータ。 > name = "スライス";ファイルタイプ:アプリケーション/オクテットストリーム

ハンドラの入力ストリームに、要求からの追加バイトを含むファイルチャンクがあることがわかりました。私は入力ストリームからファイルチャンクのサイズだけを読み込もうとしましたが、ファイルが破損しました。

私はhttp://code.msdn.microsoft.com/windowsazure/Silverlight-Azure-Blob-3b773e26からインスピレーションを得ました。単純にMVC3から標準のaspxに変換しました。

は、ここで私を助けることができる何のための

var sendFile = function (blockLength) { 
var start = 0, 
    end = Math.min(blockLength, uploader.file.size), 
    incrimentalIdentifier = 1, 
    retryCount = 0, 
    sendNextChunk, fileChunk; 
uploader.displayStatusMessage(); 
sendNextChunk = function() { 
    fileChunk = new FormData(); 
    uploader.renderProgress(incrimentalIdentifier); 
    if (uploader.file.slice) { 
     fileChunk.append('Slice', uploader.file.slice(start, end)); 
    } 
    else if (uploader.file.webkitSlice) { 
     fileChunk.append('Slice', uploader.file.webkitSlice(start, end)); 
    } 
    else if (uploader.file.mozSlice) { 
     fileChunk.append('Slice', uploader.file.mozSlice(start, end)); 
    } 
    else { 
     uploader.displayLabel(operationType.UNSUPPORTED_BROWSER); 
     return; 
    } 
    var testcode = 'http://localhost:56307/handler1.ashx?create=0&blockid=' + incrimentalIdentifier + '&filename=' + uploader.file.name + '&totalBlocks=' + uploader.totalBlocks; 
    jqxhr = $.ajax({ 
     async: true,   
     url: testcode, 
     data: fileChunk, 
     contentType: false, 
     processData:false, 
     dataType: 'text json',   
     type: 'POST', 
     error: function (request, error) { 
      if (error !== 'abort' && retryCount < maxRetries) { 
       ++retryCount; 
       setTimeout(sendNextChunk, retryAfterSeconds * 1000); 
      } 

      if (error === 'abort') { 
       uploader.displayLabel(operationType.CANCELLED); 
       uploader.resetControls(); 
       uploader = null; 
      } 
      else { 
       if (retryCount === maxRetries) { 
        uploader.uploadError(request.responseText); 
        uploader.resetControls(); 
        uploader = null; 
       } 
       else { 
        uploader.displayLabel(operationType.RESUME_UPLOAD); 
       } 
      } 

      return; 
     }, 
     success: function (notice) { 
      if (notice.error || notice.isLastBlock) { 
       uploader.renderProgress(uploader.totalBlocks + 1); 
       uploader.displayStatusMessage(notice.message); 
       uploader.resetControls(); 
       uploader = null; 
       return; 
      } 

      ++incrimentalIdentifier; 
      start = (incrimentalIdentifier - 1) * blockLength; 
      end = Math.min(incrimentalIdentifier * blockLength, uploader.file.size); 
      retryCount = 0; 
      sendNextChunk(); 
     } 
    }); 
}; 

本当にありがとうございました、aspxページへのファイルのチャンクを送信するために、AJAXを使用してコールです。

答えて

0

私のウェブフォームでは、入力ファイルのタグにenctype = "multipart/form-data"属性がありませんでした。

0

それはASPXですか? http://localhost:56307/handler1にあります。 ashx?create = 0 & blockid?

+0

aspxページの代わりにジェネリックハンドラを使用しようとしましたが、両方のオプションがまだ送信されているファイルチャンクを読み取ることができず、Request.Filesはまだ空です。 – Zephon

関連する問題