Comments (9)
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.
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.
from azure-storage-js.
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.
from azure-storage-js.
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.
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.
@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.
@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.
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)
- This repo is missing important files HOT 1
- high-level samples Abort.timeout duration HOT 2
- can I use this library in a React Native app? HOT 10
- Aborter throws timeout error even though it succeeds on download of BlockBlobUrl HOT 15
- Missing setProperties function for blob HOT 2
- Export RetryPolicyType in index.ts HOT 1
- Unable to set file HTTP headers HOT 1
- Using application/json header for file upload (x-ms-blob-type error) HOT 2
- Support for Angular4 (Typescript < 2.4) HOT 4
- how to handle viewing files that are stored in azure storage with multiple mime types HOT 7
- Cannot find name 'Event' HOT 9
- Aborter does not abort uploads that are in timeout / retrying HOT 2
- Gracefully handle 404 of reading from blob HOT 2
- [Tests] incorrect assert.ok() on result from string.indexof HOT 1
- downloadBlobToBuffer may download error ranges when customize non zero offset with count HOT 1
- Dowloading a blob should not reject on 304 HOT 3
- Question: file service API is so confusing :( :( HOT 2
- [Notice] This Project has been Moved to Azure SDK Central Repository
- How to list blobs from virtual directory in latest nodejs SDK? HOT 2
- How to get Content-MD5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-storage-js.