locked
UploadOperation multipart with more than 20 files

    Question

  • I create a BackgroundUploader with more than 20 BackgroundTransferContentPart 

    However the server only see the first 20 files.

                 

     var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader(); 

    This is my function:

             function (uri, files) {  
                    var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader(); 

                    var contentParts = [];    

                    for(var i = 0; i < files.length; i++){                    
                        var part = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart("File[]", i + "_" + files[i].name);                     
                        part.setHeader("Content-Type",files[i].contentType);
                        part.setFile(files[i]);
                        contentParts.push(part);
                    }

                    // Create a new upload operation. 

                    console.log("Files being uploaded upload: " + contentParts.length);
                    uploader.createUploadAsync(uri, contentParts, "form-data").then(function (uploadOperation) { 
                        // Start the upload and persist the promise to be able to cancel the upload. 
                        upload = uploadOperation; 
                        promise = uploadOperation.startAsync().then(complete, error, progress); 
                    }); 
                }; 

    i pass more than 20 files to it but only 20 get uploaded to the server.

    Is it possible to change the limit?


    Friday, February 14, 2014 10:39 PM

Answers

  • Your code does not look much different from what the Multipart sample http://code.msdn.microsoft.com/windowsapps/Background-Transfer-Sample-d7833f61. Infact, I replaced the code in the startMultipart function with your code and I was able to upload 24 files without any problems.

    To understand what exactly is going on, you can probably collect a Fiddler trace to understand the HTTP request & response being sent.

    While running the sample with your code, I see the following HTTP request:

    POST http://127.0.0.1/BackgroundTransferSample/Upload.aspx HTTP/1.1
    ...other HTTP headers....
    Connection: Keep-Alive
    Pragma: no-cache
    
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0
    Content-Type: text/plain
    Content-Dis-data; name="File[]"; filename="0_out.txt"
    
    ...data...
    
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0
    Content-Type: text/plain
    Content-Dis-data; name="File[]"; filename="1_out1.txt"
    
    ...data...
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0
    Content-Type: text/plain
    Content-Dis-data; name="File[]"; filename="23_out23.txt"
    
    ... data...
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0

    And here's the entire code that I replaced in the sample above which successfully sends these 24 files.

            this.startMultipart = function (uri, files) {
                printLog("Using URI: " + uri.absoluteUri + "<br/>");
    
                // forum code
                var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
                var contentParts = [];
    
                for (var i = 0; i < files.length; i++) {
                    var part = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart("File[]", i + "_" + files[i].name);
                    part.setHeader("Content-Type", files[i].contentType);
                    part.setFile(files[i]);
                    contentParts.push(part);
                }
    
                // Create a new upload operation. 
    
                console.log("Files being uploaded upload: " + contentParts.length);
                uploader.createUploadAsync(uri, contentParts, "form-data").then(function (uploadOperation) {
                    // Start the upload and persist the promise to be able to cancel the upload. 
                    upload = uploadOperation;
                    promise = uploadOperation.startAsync().then(complete, error, progress);
                });
    
                // old code
                //files.forEach(function (file, index) {
                //    var part = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart("File" + index, file.name);
                //    part.setFile(file);
                //    contentParts.push(part);
                //});
    
                //// Create a new upload operation.
                //uploader.createUploadAsync(uri, contentParts).then(function (uploadOperation) {
                //    // Start the upload and persist the promise to be able to cancel the upload.
                //    upload = uploadOperation;
                //    promise = uploadOperation.startAsync().then(complete, error, progress);
                //});
            };


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Saturday, February 15, 2014 2:02 AM
    Moderator

All replies

  • Your code does not look much different from what the Multipart sample http://code.msdn.microsoft.com/windowsapps/Background-Transfer-Sample-d7833f61. Infact, I replaced the code in the startMultipart function with your code and I was able to upload 24 files without any problems.

    To understand what exactly is going on, you can probably collect a Fiddler trace to understand the HTTP request & response being sent.

    While running the sample with your code, I see the following HTTP request:

    POST http://127.0.0.1/BackgroundTransferSample/Upload.aspx HTTP/1.1
    ...other HTTP headers....
    Connection: Keep-Alive
    Pragma: no-cache
    
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0
    Content-Type: text/plain
    Content-Dis-data; name="File[]"; filename="0_out.txt"
    
    ...data...
    
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0
    Content-Type: text/plain
    Content-Dis-data; name="File[]"; filename="1_out1.txt"
    
    ...data...
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0
    Content-Type: text/plain
    Content-Dis-data; name="File[]"; filename="23_out23.txt"
    
    ... data...
    --13a1ef13-4bc3-4097-bc5b-17e5d47fdcd0

    And here's the entire code that I replaced in the sample above which successfully sends these 24 files.

            this.startMultipart = function (uri, files) {
                printLog("Using URI: " + uri.absoluteUri + "<br/>");
    
                // forum code
                var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
                var contentParts = [];
    
                for (var i = 0; i < files.length; i++) {
                    var part = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart("File[]", i + "_" + files[i].name);
                    part.setHeader("Content-Type", files[i].contentType);
                    part.setFile(files[i]);
                    contentParts.push(part);
                }
    
                // Create a new upload operation. 
    
                console.log("Files being uploaded upload: " + contentParts.length);
                uploader.createUploadAsync(uri, contentParts, "form-data").then(function (uploadOperation) {
                    // Start the upload and persist the promise to be able to cancel the upload. 
                    upload = uploadOperation;
                    promise = uploadOperation.startAsync().then(complete, error, progress);
                });
    
                // old code
                //files.forEach(function (file, index) {
                //    var part = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart("File" + index, file.name);
                //    part.setFile(file);
                //    contentParts.push(part);
                //});
    
                //// Create a new upload operation.
                //uploader.createUploadAsync(uri, contentParts).then(function (uploadOperation) {
                //    // Start the upload and persist the promise to be able to cancel the upload.
                //    upload = uploadOperation;
                //    promise = uploadOperation.startAsync().then(complete, error, progress);
                //});
            };


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Saturday, February 15, 2014 2:02 AM
    Moderator
  • Probably some server issue then.

    Thank you.

    Saturday, February 15, 2014 12:19 PM