This commit is contained in:
Ilya Kantor 2019-07-08 14:08:07 +03:00
parent 5e9eca374f
commit f30e0d4722
4 changed files with 38 additions and 28 deletions

View file

@ -32,14 +32,15 @@ function onUpload(req, res) {
let fileStream;
// for byte 0, create a new file, otherwise check the size and append to existing one
if (startByte == 0) {
// if startByte is 0 or not set, create a new file, otherwise check the size and append to existing one
if (!startByte) {
upload.bytesReceived = 0;
fileStream = fs.createWriteStream(filePath, {
flags: 'w'
});
debug("New file created: " + filePath);
} else {
// we can check on-disk file size as well to be sure
if (upload.bytesReceived != startByte) {
res.writeHead(400, "Wrong start byte");
res.end(upload.bytesReceived);

View file

@ -5,7 +5,7 @@ class Uploader {
this.onProgress = onProgress;
// create fileId that uniquely identifies the file
// we can also add user session identifier, to make it even more unique
// we could also add user session identifier (if had one), to make it even more unique
this.fileId = file.name + '-' + file.size + '-' + +file.lastModifiedDate;
}