2011-12-29 19 views
5

Bir dosyayı doğrudan maskeleme deposuna sığdırmaya çalışan bir sorun yaşıyorum. Bir külçe işleyicisine posta istekleri göndermek için ajax çağrıları kullanıyorum. Çalıştığım sorun, işleyicinin ajax postasından gönderilen filechunk'u almamasıdır.Azure'a Yükleme

ben sayfa kundakçı istek bakmaktan doğru yazı alıyor görebilirsiniz

---------------------- ------- 265001916915724 İçerik-Atma: form-veri; > Name = "Dilim"; filename = "blob" İçerik türü: application/octet-stream

İşleyicideki giriş akışının, istek üzerine ek bayt dahil olmak üzere, filechunk'u olduğunu fark ettim. Giriş dosyasının yalnızca filechunk boyutunu okumayı denedim, ancak bu bozuk bir dosyaya neden oldu.

http://code.msdn.microsoft.com/windowsazure/Silverlight-Azure-Blob-3b773e26'dan ilham aldım, basitçe MVC3'ten standart aspx kullanmaya dönüştürdüm.

Burada bana yardım edebilir şey için

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(); 
     } 
    }); 
}; 

Çok teşekkürler, aspx sayfasına dosya yığın göndermek için ajax kullanarak çağrıdır.

cevap

0

Webformumu açtığımda, giriş dosyası etiketinde enctype = "multipart/form-data" özniteliği yoktu.

0

Bu ASPX amacı nedir? http://localhost:56307/handler1. ashx? Create = 0 & blockid?

+0

Amaç, aspx sayfası yerine bir genel işleyici kullanmayı denedim, ancak her iki seçenek de gönderilen filechunk öğelerini hala okuyamıyor, Request.Files hala boş. – Zephon

İlgili konular