我目前正在使用此代码从本地磁盘选择一个文件到我的 api:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$(':file').on('change', function () {
var file = this.files[0];
if (file.type !== "video/mp4" && file.type!== "video/quicktime") {
alert("Content must be video .mp4 or .mov")
}
$(':button').on('click', function () {
if (file.type == "video/mp4" || file.type == "video/quicktime"){
$.ajax({
// Your server script to process the upload
url: 'azureAPI',
type: 'POST',
// Form data
data: new FormData($('form')[0]),
// Tell jQuery not to process data or worry about content-type
// You *must* include these options!
cache: false,
contentType: false,
processData: false,
// Custom XMLHttpRequest
xhr: function () {
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
// For handling the progress of the upload
myXhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable) {
$('progress').attr({
value: e.loaded,
max: e.total,
});
}
}, false);
}
return myXhr;
}
});
} else {
alert ("File type must be .mp4 or .mov")
}
});
});
});
</script>
这会以以下形式发送(我假设是)二进制数据:
���
1!QAa"q2B���R�#3br��u�����S6C$%��5�cts�T&D4��U��d���e!1AQa2"q�#����3��B���X"��?��!=��W�u�ٗ�-2���?����ۯ�Կ�i���t����M���Y�-��-Vdϊ�P�<�<U#TY]K��dW
���
我正在使用 Azure,现在尝试将其发送到 Microsoft Video Indexer,它表示将数据作为正文中的 multipart/form-data 发送。(见https://api-portal.videoindexer.ai/docs/services/Operations/operations/Upload-Video?)
我尝试在正文中发送二进制数据,但它说它需要字符串/缓冲区。
然后我尝试将正文中的二进制数据发送为var body = Buffer.from(req.body,'binary')
哪个发送了,但 VI 回复说索引数据存在问题,可能是因为我发送的编码错误?
为了解决这个问题,我现在尝试先将该二进制数据保存到块 blob,然后我将调用该 url,但是我无法使用以下方法将二进制数据保存到 Azure 块 blob:
var buf = Buffer.from(req.body, 'binary');
blobService.createBlockBlobFromText(container, 'fileName.mp4', buf, {contentSettings: {contentType: 'video/mp4', contentEncoding: 'binary'}}, function (error, result, response) {
if(!error){
callback('uploaded');
} else {
callback('nope');
}
});
我尝试了这个,一开始没有contentSettings
,但将数据保存为contentType: application/octet-stream
未作为视频打开的数据。然后我添加了contentType
,并继续尝试添加contentEncoding
。
这保存了正确的contentType
但仍然无法打开视频。
有谁知道如何正确编码数据以首先直接发送到视频索引器,或者其次将二进制数据保存到 Azure blob 存储?
感谢您的任何指点,如果我遗漏了任何内容,我们深表歉意。