我尝试使用下面链接中的Azure Media服务引用代码上传视频。
请求标题如下所示
Request: PUT /asset-967889d1-bb0d-4853-9e61-31777d9b3f4e/Wildlife.wmv?sv=2012-02-12&sr=c&si=39af4b60-16ac-4abe-8a2f-4fdf7a90e1f3&sig=pukmGXpkVJuD4zqFm6xoCRBgGWjphO8%2BP8BtfK0GUV4%3D&st=2017-06-15T17%3A20%3A18Z&se=2017-06-30T17%3A20%3A18Z&comp=blocklist HTTP/1.1
Accept: */*
Content-Type: video/x-ms-wmv
x-ms-blob-content-type: video/x-ms-wmv
Referer: http://localhost:56509/Admin/Users
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: ourhost.net
Content-Length: 7164
DNT: 1
Connection:Keep-Alive
Cache-Control: no-cache
示例请求正文:
<?xml version="1.0" encoding="utf-8"?>
<BlockList><Latest>YmxvY2stMDAwMDAw</Latest>
<Latest>YmxvY2stMDAwMDAwMQ==</Latest>
</BlockList>
在响应正文中抛出错误:
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidBlockList</Code><Message>The specified block list is invalid.
RequestId:0e320a80-0001-001f-06fb-e59187000000
Time:2017-06-15T17:21:29.5286217Z</Message></Error>
请指点解决此问题。
更新:我在第一个块ID中追加另一个0。
现在我的请求正文如下:
<?xml version="1.0" encoding="utf-8"?>
<BlockList>
<Latest>YmxvY2stMDAwMDAwMA==</Latest>
<Latest>YmxvY2stMDAwMDAwMQ==</Latest>
<Latest>YmxvY2stMDAwMDAwMg==</Latest>
<Latest>YmxvY2stMDAwMDAwMw==</Latest>
</BlockList>
在响应正文中引发相同的错误。
<?xml version="1.0" encoding="utf-8"?>
<Error><Code>InvalidBlockList</Code>
<Message>The specified block list is invalid.
RequestId:520e710f-0001-0008-4165-e651e4000000
Time:2017-06-16T06:01:04.0358396Z</Message></Error>
Javascript致电:
// Getting the File Data from the Uploaded Html Filetype="Input"
var fileData = $("#mediatypeUpload")[0].files[0];
// Getting the Sas Url with Signature
var TSasUrl = data.Path;
var iqs = TSasUrl.indexOf("?");
LocatorId = data.Id;
SasUrl = TSasUrl.substring(0, iqs) + '/' + fileData.name + TSasUrl.substring(iqs);
var reader = new FileReader();
var fileContent = selectedFile.slice(currentFilePointer, currentFilePointer + maxBlockSize);
reader.readAsArrayBuffer(fileContent);
//Upload the File
reader.onloadend = function (evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
var requestData = new Uint8Array(evt.target.result);
var blockId = blockIdPrefix + pad(blockIds.length, 7);
console.log("block id = " + blockId);
blockIds.push(btoa(blockId));
var uri = SasUrl + '&comp=block&blockid=' + blockIds[blockIds.length - 1];
$.ajax({
url: uri,
crossDomain: true,
type: "PUT",
data: requestData,
processData: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob');
xhr.setRequestHeader('Content-Length', requestData.length);
},
success: function (data, status) {
console.log(data);
console.log(status);
bytesUploaded += requestData.length;
var percentComplete = ((parseFloat(bytesUploaded) / parseFloat(selectedFile.size)) * 100).toFixed(2);
$("#fileUploadProgress").text(percentComplete + " %");
uploadFileInBlocks();
},
error: function (xhr, desc, err) {
console.log('Final ---- ' + desc);
console.log('Final ------ ' + err);
}
});
}
};
function uploadFileInBlocks() {
if (totalBytesRemaining > 0) {
console.log("current file pointer = " + currentFilePointer + " bytes read = " + maxBlockSize);
var fileContent = selectedFile.slice(currentFilePointer, currentFilePointer + maxBlockSize);
var blockId = blockIdPrefix + pad(blockIds.length, 7);
console.log("block id = " + blockId);
blockIds.push(btoa(blockId));
reader.readAsArrayBuffer(fileContent);
currentFilePointer += maxBlockSize;
totalBytesRemaining -= maxBlockSize;
if (totalBytesRemaining < maxBlockSize) {
maxBlockSize = totalBytesRemaining;
}
} else {
commitBlockList();
}
}
function commitBlockList() {
var uri = SasUrl + '&comp=blocklist';
console.log(uri);
var requestBody = '<?xml version="1.0" encoding="utf-8"?><BlockList>';
for (var i = 0; i < blockIds.length; i++) {
requestBody += '<Latest>' + blockIds[i] + '</Latest>';
}
requestBody += '</BlockList>';
console.log(requestBody);
alert('Req ' + requestBody);
$.ajax({
url: uri,
type: "PUT",
data: requestBody,
contentType: 'application/xml',
beforeSend: function (xhr) {
alert('2' +requestBody);
xhr.setRequestHeader('x-ms-blob-content-type', selectedFile.type);
xhr.setRequestHeader('Content-Length', requestBody.length);
},
success: function (data, status) {
console.log(data);
console.log(status);
},
error: function (xhr, desc, err) {
console.log(desc);
console.log(err);
}
});
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
Html代码:
<div class="form-group row">
<div class="col-xs-6">
<label>Media Type</label>
<select placeholder="" class="form-control" id="mediatypeSelect">
<option value="">- Select -</option>
<option value="document">Document</option>
<option value="image">Image</option>
<option value="audio">Audio</option>
<option value="video">Video</option>
</select>
</div>
<div class="col-xs-6">
<label>Upload File</label>
<input type="file" class="form-control" id="mediatypeUpload" >
<div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
<span id="fileUploadProgress" class="sr-only">0% Complete</span>
</div>
</div>
<br />
<div id="fileName"></div>
<div id="fileSize"></div>
<div id="fileType"></div>
</div>
</div>
<div class="form-group text-right">
<button type="button" class="btn btn-primary" id="btnAddResource">Add</button>
<button type="button" class="btn btn-primary" id="cancelResource">Cancel</button>
</div>
答案 0 :(得分:1)
您收到此错误的原因是a.setSize(275, 180);
的长度不同。根据文档here
(请参阅URI参数部分),块ID必须具有相同的长度。
如果我这样做:
block ids
我得到Encoding.UTF8.GetString(Convert.FromBase64String("YmxvY2stMDAwMDAw"));
如果我对你的第二个区块ID做同样的事情:
block-000000
我得到Encoding.UTF8.GetString(Convert.FromBase64String("YmxvY2stMDAwMDAwMQ=="));
的输出。
正如您所看到的,块ID长度为2不同(第一个是12个字符,第二个是13个字符)。请将第一个块ID更改为block-0000001
(基本上附加另一个block-0000000
)然后此错误应该消失。