0

i am trying to upload a file from front-end to backend and store the file on azurestorage, my code works fine when the file size is less than 30mb, but if file size is great than 30mb does not work

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

if file is great than 30mb no console.log is displayed.

in localhost it works everytime, also if size is great than 30mb (i tested with 104mb file) but when code is in azure (azurewebsites), it does not work

express: v4.16.4 node: v12.16.2

Alex
  • 93
  • 1
  • 1
  • 5
  • By default you indeed have a max size of 30,000,000 bytes (~28.6MB). In `c#` you would configure this by changing the max allowed content length setting in the `web.config`. I assume you would do something similar with `node.js`, but as I don't work with it I can't give you specifics on that. Hopefully this will point you in the right direction for your searches though ;) – NotFound May 14 '20 at 12:32

1 Answers1

0

i solved it using this on web.config

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

Alex
  • 93
  • 1
  • 1
  • 5