Reputation: 63
Now, I am trying to upload a large size file(2.75GB). When I tried to upload the large size file then the NodeJS server dies and give me the below errors. Other small files can be uploaded. OTL
node[38948]: ../src/node_file.cc:1833:void node::fs::WriteBuffer(const FunctionCallbackInfo<v8::Value> &): Assertion `args[3]->IsInt32()' failed.
1: 0x10009ce91 node::Abort() [/usr/local/bin/node]
2: 0x10009cd1a node::AppendExceptionLine(node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Message>, node::ErrorHandlingMode) [/usr/local/bin/node]
3: 0x1000ac108 node::fs::WriteBuffer(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
4: 0x10021da46 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/usr/local/bin/node]
5: 0x10021d0c9 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
6: 0x10021c8b0 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
7: 0x1007fd979 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/usr/local/bin/node]
8: 0x100796ae2 Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]
Setup
// package.json
...
"scripts": {
"start": "node --max-old-space-size=4096 ./bin/www"
},
...
// app.js
const fileUpload = require('express-fileupload');
app.use(fileUpload());
// upload.js
const session = await mongoose.startSession();
session.startTransaction();
try {
const result = await Storage.create([attachment], {session: session});
await req.files.newFile.mv(attachment.filePath);
await session.commitTransaction();
return res.send(result[0]);
} catch (err) {
const message = "Can't save the attachment.";
console.error(message, err);
await session.abortTransaction();
return res.status(500).send(message);
} finally {
session.endSession();
}
Upvotes: 1
Views: 1849
Reputation: 314
as mentioned in express-fileup you can add limit.
app.use(fileUpload({
limits: { fileSize: 50 * 1024 * 1024 },
}));
and for large files as suggested in docs, Use temp files instead of memory for managing the upload process.
// Note that this option available for versions 1.0.0 and newer.
app.use(fileUpload({
useTempFiles : true,
tempFileDir : '/tmp/'
}));
you can read there documentation for more details
Upvotes: 3