Giter Site home page Giter Site logo

Comments (9)

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024 3

Examples comparing V2 vs V10 for uploading a File in browsers:

V10

      function uploadBlobByStream(checkMD5) {
        var files = document.getElementById("files").files;
        if (!files.length) {
          alert("Please select a file!");
          return;
        }
        var file = files[0];
        var blobServiceURL = getBlobServiceURL();
        if (!blobServiceURL) {
          return;
        }

        var containerURL = azblob.ContainerURL.fromServiceURL(
          blobServiceURL,
          container
        );
        var blockBlobURL = azblob.BlockBlobURL.fromContainerURL(
          containerURL,
          file.name
        );

        var btn = document.getElementById("upload-button");
        btn.disabled = true;
        btn.innerHTML = "Uploading";

        var blockSize = 4 * 1024 * 1024;

        azblob
          .uploadBrowserDataToBlockBlob(
            azblob.Aborter.none,
            file,
            blockBlobURL,
            {
              blockSize: blockSize,
              progress: function(ev) {
                displayProcess((ev.loadedBytes * 100) / file.size);
              }
            }
          )
          .then(function() {
            btn.disabled = false;
            btn.innerHTML = "UploadBlob";
            displayProcess(100);
            setTimeout(function() {
              // Prevent alert from stopping UI progress update
              alert("Upload successfully!");
            }, 1000);
            refreshBlobList();
          })
          .catch(function(error) {
            btn.disabled = false;
            btn.innerHTML = "UploadBlob";
            alert("Upload filed, open browser console for more detailed info.");
            console.log(error);
            displayProcess(0);
          });
      }

V2

function uploadBlobByStreamOld(checkMD5) {
        var files = document.getElementById("files").files;
        if (!files.length) {
          alert("Please select a file!");
          return;
        }
        var file = files[0];

        var blobService = getBlobService();
        if (!blobService) return;

        var btn = document.getElementById("upload-button");
        btn.disabled = true;
        btn.innerHTML = "Uploading";

        // Make a smaller block size when uploading small blobs
        var blockSize =
          file.size > 1024 * 1024 * 32 ? 1024 * 1024 * 4 : 1024 * 512;
        var options = {
          storeBlobContentMD5: checkMD5,
          blockSize: blockSize
        };
        blobService.singleBlobPutThresholdInBytes = blockSize;

        var finishedOrError = false;
        var speedSummary = blobService.createBlockBlobFromBrowserFile(
          container,
          file.name,
          file,
          options,
          function(error, result, response) {
            finishedOrError = true;
            btn.disabled = false;
            btn.innerHTML = "UploadBlob";
            if (error) {
              alert(
                "Upload filed, open brower console for more detailed info."
              );
              console.log(error);
              displayProcess(0);
            } else {
              displayProcess(100);
              setTimeout(function() {
                // Prevent alert from stopping UI progress update
                alert("Upload successfully!");
              }, 1000);
              refreshBlobList();
            }
          }
        );

        speedSummary.on("progress", function() {
          var process = speedSummary.getCompletePercent();
          displayProcess(process);
        });
      }

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

@varghesep

V10 is next generation of Azure Storage JavaScript SDK. It has new architecture and design, more compatibility and lightweight. You can continue to use V2, or considering moving to V10.

For V2, only way to use the browser version is to load the JS bundle. While for V10, you can directly import the @azure/storage-blob npm package.

In V2, createBlockBlobFromBrowserFile only accepts File. While for V10, uploadBrowserDataToBlockBlob accepts Blob | ArrayBuffer | ArrayBufferView. File inherits from Blob, so it accepts File too.

https://docs.microsoft.com/en-us/javascript/api/%40azure/storage-blob/index?view=azure-node-preview#uploadbrowserdatatoblockblob-aborter--blob---arraybuffer---arraybufferview--blockbloburl--iuploadtoblockbloboptions-

from azure-storage-js.

varghesep avatar varghesep commented on May 28, 2024

I followed your code for the version V10 and was able to successfully upload a Html5 File object (a jpeg image) from my laptop through the browser.

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

from azure-storage-js.

raufdean avatar raufdean commented on May 28, 2024

Implemented both the V2 & V10 methods as above. Over a slow patchy wifi connection the V10 method failed repeatedly. The V2 method was however very reliable. Would you have any idea why this might be the case ?

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

@raufdean

Can you share the parameters you have used? Such as file size, blockSize, parallelism/concurrency, retry settings and etc.

Error messages printed by V10 are also very helpful.

V10 enables retry policy by default, while V2 not. It's interesting V2 is more reliable on your side.

from azure-storage-js.

raufdean avatar raufdean commented on May 28, 2024

@XiaoningLiu Sure. So small files were ok, but anything over 20Mb seemed to be a problem (this was a very unreliable connection). The upload would progress, and then fail right at the end. I tried with paralleism set to 1, and reduced blocksize to 1024 x 512 but still had the same problem. The error was always a ERR_CONNECTION_RESET from Azure. I have some HAR files that I can send you directly. I then used your V2 code above, and the uploads of the same files over the same connection were fine

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

@raufdean If file size less than maxSingleShotSize (default is 256MB in bytes), file will be uploaded via a single http request. So besides setting blocksize to 1024 x 512, you need to set a small maxSingleShotSize such as 1024 * 512 to make the blocksize work. Have a try.

Please share the HAR files. What I can do is to make retry policy work for that kind of errors.

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

Will close this issue as long time no response, fell free to re-open if you have further questions.

from azure-storage-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.