When I try to upload blobs to my azure storage account I get the following error response
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>OutOfRangeInput</Code>
<Message>One of the request inputs is out of range.
RequestId:--------------------------
Time:2017-10-29T07:13:37.4218874Z
</Message>
</Error>
I am uploading multiple blobs of which some are uploaded successfully while others are not. The ones that throw the error have large blob-names (about 100 characters) so assume it may be due to blob-names size. But according to https://blogs.msdn.microsoft.com/jmstall/2014/06/12/azure-storage-naming-rules/ the maximum blob-names can be 1024 and my blob-names are way less than that limit.
An example blob-name would be "65/36/aluminium_03_group67_product_02pCube1_product_02group2_product_02Flow000_Albedo.png"
Edit Code to upload the blob.
The code to upload is in Javascript. I am breaking the file into multiple chunks and uploading. Here is the function responsible for uploading files
function AzureFileUpload(file, uploadUrl, successCallback, progressCallback, errorCallback){
this.file = file;
this.uploadUrl = uploadUrl;
this.successCallback = successCallback;
this.progressCallback = progressCallback;
this.errorCallback = errorCallback;
this.reader = new FileReader();
this.maxBlockSize = 256 * 1024;
this.blockIds = [];
this.totalBytesRemaining = this.file.size;
this.currentFilePointer = 0;
this.bytesUploaded = 0;
this.uploadFlag = true;
var self = this;
this.reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
var uri = self.uploadUrl + '&comp=block&blockid=' + self.blockIds[self.blockIds.length - 1];
var requestData = new Uint8Array(evt.target.result);
self.ReadBlock();
if(self.uploadFlag){
self.UploadBlock(requestData, uri);
}
}
};
this.ReadBlock();
}
AzureFileUpload.prototype.UploadBlock = function(requestData, blockUrl){
var self = this;
$.ajax({
url: blockUrl,
type: "PUT",
data: requestData,
processData: false,
beforeSend: function(xhr) {
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob');
xhr.setRequestHeader('x-ms-blob-cache-control', "public, max-age=864000");
},
success: function(data, status) {
self.UpdateProgress(requestData.length);
self.bytesUploaded += requestData.length;
if (parseFloat(self.bytesUploaded) == parseFloat(self.file.size)) {
self.CommitBlocks();
}
},
error: function(xhr, desc, err) {
// console.log(desc);
// console.log(err);
self.Error("Unexpected error occured while uploading model. Plaese try after some time");
}
});
};
AzureFileUpload.prototype.pad = function(number, length){
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
};
AzureFileUpload.prototype.ReadBlock = function(){
if (this.totalBytesRemaining > 0) {
var fileContent = this.file.slice(this.currentFilePointer, this.currentFilePointer + this.maxBlockSize);
var blockId = "block-" + this.file.name + "-" + this.pad(this.blockIds.length, 6);
this.blockIds.push(btoa(blockId));
this.reader.readAsArrayBuffer(fileContent);
this.currentFilePointer += this.maxBlockSize;
this.totalBytesRemaining -= this.maxBlockSize;
if (this.totalBytesRemaining < this.maxBlockSize) {
this.maxBlockSize = this.totalBytesRemaining;
}
}
};
AzureFileUpload.prototype.UpdateProgress = function(bytesUploaded){
console.log("Progress",bytesUploaded);
if(this.progressCallback){
this.progressCallback(bytesUploaded);
}
};
AzureFileUpload.prototype.CommitBlocks = function(){
var self = this;
var uri = this.uploadUrl + '&comp=blocklist';
var request = '<?xml version="1.0" encoding="utf-8"?><BlockList>';
for (var i = 0; i < this.blockIds.length; i++) {
request += '<Latest>' + this.blockIds[i] + '</Latest>';
}
request += '</BlockList>';
$.ajax({
url: uri,
type: "PUT",
data: request,
beforeSend: function(xhr) {
xhr.setRequestHeader('x-ms-blob-content-type', self.file.type);
xhr.setRequestHeader('x-ms-blob-cache-control', "public, max-age=864000");
},
success: function(data, status) {
console.log("Block Commited", data);
if(self.successCallback){
self.successCallback();
}
},
error: function(xhr, desc, err) {
self.Error("Unexpected error occured while uploading model. Plaese try after some time");
}
});
};
AzureFileUpload.prototype.Error = function(msg){
this.CancelUpload();
if(this.errorCallback){
this.errorCallback(msg);
}
};
AzureFileUpload.prototype.CancelUpload = function(){
this.uploadFlag = false;
};