快速限制文件大小 azurewebsites.



我正在尝试将文件从前端上传到后端并将文件存储在 AzureStorage 上,当文件大小小于 30MB 时,我的代码工作正常,但如果文件大小大于 30MB,则不起作用

console.log('- 11111 -')
let fileObj = {};
let companyId = 'tetst';
var datetimestamp = Date.now();
var aux = Math.floor((Math.random() * 1000) + 100);
datetimestamp = datetimestamp + aux.toString();
let percentage = 0;
let body = req.body;
console.log('- 1122112 -')

let tran;
try {
console.log('- 1 -')
var blobService = azureStorage.createBlobService(storageConnectionString);
var form = new multiparty.Form();
await form.on('part', async function(part) {
if (part.filename) {
console.log('- 2 -')
var size = part.byteCount;
fileObj.originalname = part.filename;
fileObj.contenttype = part.headers['content-type'];
var name = companyId +'/' + datetimestamp + '.' +part.filename.split('.')[part.filename.split('.').length -1];
fileObj.name = name;
await blobService.createBlockBlobFromStream(container, name, part, size, async function(error, result, response) {
if (error) {
res.status(409).send({ Grrr: error });
return;
}
console.log('- 22 -')
fileObj.BlobResult = result;
fileObj.response = response;
res.status(201).send();
});
} else {
form.handlePart(part);
}
part.resume();
});

// Close emitted after form parsed
await form.on('close', function() {
console.log('Upload completed!');
});
await form.on('aborted', () => {
console.log('aborted!!!')
});
// Errors may be emitted
// Note that if you are listening to 'part' events, the same error may be
// emitted from the `form` and the `part`.
await form.on('error', function(err) {
console.log('Error parsing form: ' + err.stack);
res.status(400).send(err);
});
// Parse req
form.parse(req);
}
catch(err) {        
next(err);
}

如果文件大于 30MB,则不显示控制台.log。

在本地主机中,它每次都可以工作,如果大小大于 30MB(我用 104MB 文件进行了测试(,但是当代码在 Azure(Azure网站(中时,它不起作用

快速版:v4.16.4 节点:v12.16.2

我在web.config上使用它解决了它

<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>

相关内容

  • 没有找到相关文章

最新更新