gpt4 book ai didi

Azure Blob 存储 : 400 (One of the request inputs is out of range.)

转载 作者:行者123 更新时间:2023-12-04 14:25:15 24 4
gpt4 key购买 nike

当我尝试将 blob 上传到我的 Azure 存储帐户时,收到以下错误响应

<?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>

我正在上传多个 blob,其中一些已成功上传,而另一些则未成功。引发错误的错误具有较大的 blob 名称(大约 100 个字符),因此假设这可能是由于 blob 名称大小所致。但根据https://blogs.msdn.microsoft.com/jmstall/2014/06/12/azure-storage-naming-rules/最大 blob 名称可以是 1024,而我的 blob 名称远小于该限制。

示例 blob 名称为“65/36/aluminium_03_group67_product_02pCube1_product_02group2_product_02Flow000_Albedo.png”

编辑代码以上传 blob。

要上传的代码是 JavaScript 代码。我正在将文件分成多个 block 并上传。这里是负责上传文件的函数

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

最佳答案

问题出在以下代码行:

var blockId = "block-" + this.file.name + "-" + this.pad(this.blockIds.length, 6);

本质上, block ID 的最大长度可以是 64 字节(引用:https://learn.microsoft.com/en-us/rest/api/storageservices/put-block - 请参阅 URI 参数部分)。由于您在 block ID 计算中包含文件名,并且您的文件名很大,因此超出了此限制。

请尝试使用以下代码行,您应该不会收到此错误:

var blockId = "block-" + this.pad(this.blockIds.length, 6);

请注意, block ID 的范围仅限于 Blob,因此您实际上没有必要包含 Blob 名称来使 block ID 对于 Blob 来说是唯一的。

关于Azure Blob 存储 : 400 (One of the request inputs is out of range.),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46997836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com