FineUploader / fine-uploader

Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.
https://fineuploader.com
MIT License
8.18k stars 1.87k forks source link

Not working as a service (nodejs Ubuntu) #2041

Closed Anson-Zhao closed 6 years ago

Anson-Zhao commented 6 years ago

Type of issue

Uploader type

Note: Support requests cannot be accepted due to lack of time.

Bug Report When I use my node js app as an instance, the fine-uploader works fine. When I use my node js app as a service, fine-uploader refuse to upload files. #### Fine Uploader version {example: 5.5.1} 5.16.2 #### Browsers where the bug is reproducible {example: "Firefox" and "IE11"} Chrome 67.0.3396.99 (Official Build) (64-bit) #### Operating systems where the bug is reproducible {example: "iOS 9.1.0" and "Windows 8.1"} Client Side OS: Mac OS 10.13.6 Server Side OS: Ubuntu 16.04, Node JS v8.9.1 #### Exact steps required to reproduce the issue For example: 1. Set up Ubuntu server 16.04 with Node js v8.9.1 2. Put all node js application with node module library onto Ubuntu server 3. Go to node js application folder, run "node app.js" as an instance 4. Fine-uploader works fine 5. Use systemd to set up node js application as a service "service-A" 6. Start "service-A", and fine-uploader refused to upload. It just said nothing, just error code "Exit-1", in journalctl -u service-A #### All relevant Fine Uploader-related code that you have written {simply copy and paste the JS used to control Fine Uploader browsers-ide} {also include your template HTML if related to a UI issue} USGS Data Visualization - WMS Layer Customized Request

Layer Request Form

Layer Information

Please enter the layer name. NOTE: Do not include spaces.

Please include the image resolution, drone altitude, date created and other conditions.


Cancel

#### Your Fine Uploader template markup (if using Fine Uploader UI and the issue is UI-related) {simply copy and paste your template markup} #### Server side code app.post('/upload', onUpload); function onUpload(req, res, next) { res.setHeader("Access-Control-Allow-Origin", "*"); // Allow cross domain header let form = new multiparty.Form(); form.parse(req, function (err, fields, files) { // console.log(fields); let partIndex = fields.qqpartindex; // text/plain is required to ensure support for IE9 and older res.set("Content-Type", "text/plain"); if (partIndex == null) { onSimpleUpload(fields, files[fileInputName][0], res); } else { onChunkedUpload(fields, files[fileInputName][0], res); } }); } let responseDataUuid = "", responseDataName = "", responseDataUuid2 = "", responseDataName2 = ""; function onSimpleUpload(fields, file, res) { res.setHeader("Access-Control-Allow-Origin", "*"); // Allow cross domain header responseDataUuid = ""; let d = new Date(), uuid = d.getUTCFullYear() + "-" + ('0' + (d.getUTCMonth() + 1)).slice(-2) + "-" + ('0' + d.getUTCDate()).slice(-2) + "T" + ('0' + d.getUTCHours()).slice(-2) + ":" + ('0' + d.getUTCMinutes()).slice(-2) + ":" + ('0' + d.getUTCSeconds()).slice(-2) + "Z", responseData = { success: false, newuuid: uuid + "_" + fields.qqfilename // newuuid2: uuid + "_" + fields.qqfilename }; responseDataUuid = responseData.newuuid; // responseDataUuid2 = responseData.newuuid2; file.name = fields.qqfilename; responseDataName = file.name; responseDataName2 = file.name; // console.log("forth hokage: " + responseDataUuid); // console.log("fifth harmony: " + responseDataName); // console.log("trials 4 days: " + responseDataUuid2); // console.log("pentatonic success: " + responseDataName2); if (isValid(file.size)) { moveUploadedFile(file, uuid, function () { responseData.success = true; res.send(responseData); }, function () { responseData.error = "Problem copying the file!"; res.send(responseData); }); } else { failWithTooBigFile(responseData, res); } } function onChunkedUpload(fields, file, res) { res.setHeader("Access-Control-Allow-Origin", "*"); // Allow cross domain header console.log("Z"); let size = parseInt(fields.qqtotalfilesize), uuid = fields.qquuid, index = fields.qqpartindex, totalParts = parseInt(fields.qqtotalparts), responseData = { success: false }; file.name = fields.qqfilename; if (isValid(size)) { storeChunk(file, uuid, index, totalParts, function () { if (index < totalParts - 1) { responseData.success = true; res.send(responseData); } else { combineChunks(file, uuid, function () { responseData.success = true; res.send(responseData); }, function () { responseData.error = "Problem conbining the chunks!"; res.send(responseData); }); } }, function (reset) { responseData.error = "Problem storing the chunk!"; res.send(responseData); }); } else { failWithTooBigFile(responseData, res); } } function failWithTooBigFile(responseData, res) { res.setHeader("Access-Control-Allow-Origin", "*"); // Allow cross domain header responseData.error = "Too big!"; responseData.preventRetry = true; res.send(responseData); } //delete new photo function onDeleteFile1(req, res) { res.setHeader("Access-Control-Allow-Origin", "*"); // Allow cross domain header console.log("result=" + req.params.uuid); let uuid = req.params.uuid, dirToDelete = "uploadfiles/" + uuid; rimraf(dirToDelete, function(error) { if (error) { console.error("Problem deleting file! " + error); res.status(500); } res.send(); }); } //delete old photo function onDeleteFile2(req, res) { res.setHeader("Access-Control-Allow-Origin", "*"); // Allow cross domain header let dirToDelete = "uploadfiles/" + olduuid[0].Layer_Uploader_name; rimraf(dirToDelete, function(error) { if (error) { console.error("Problem deleting file! " + error); res.status(500); } res.send(); }); } function isValid(size) { return maxFileSize === 0 || size < maxFileSize; } function moveFile(destinationDir, sourceFile, destinationFile, success, failure) { console.log(destinationDir); mkdirp(destinationDir, function (error) { let sourceStream, destStream; if (error) { console.error("Problem creating directory " + destinationDir + ": " + error); failure(); } else { sourceStream = fs.createReadStream(sourceFile); destStream = fs.createWriteStream(destinationFile); sourceStream .on("error", function (error) { console.error("Problem copying file: " + error.stack); destStream.end(); failure(); }) .on("end", function () { destStream.end(); success(); }) .pipe(destStream); } }); // let sourceStream = fs.createReadStream(sourceFile); // let destStream = fs.createWriteStream(destinationFile); // // sourceStream.on("error", function (error) { // console.error("Problem copying file: " + error.stack); // destStream.end(); // failure(); // }).on("end", function () { // destStream.end(); // success(); // }).pipe(destStream); } function moveUploadedFile(file, uuid, success, failure) { let destinationDir = "uploadfiles/", fileDestination = destinationDir + uuid + "_" + file.name; moveFile(destinationDir, file.path, fileDestination, success, failure); } function storeChunk(file, uuid, index, numChunks, success, failure) { let destinationDir = uploadedFilesPath + uuid + "/" + chunkDirName + "/", chunkFilename = getChunkFilename(index, numChunks), fileDestination = destinationDir + chunkFilename; moveFile(destinationDir, file.path, fileDestination, success, failure); } function combineChunks(file, uuid, success, failure) { let chunksDir = uploadedFilesPath + uuid + "/" + chunkDirName + "/", destinationDir = uploadedFilesPath + uuid + "/", fileDestination = destinationDir + file.name; fs.readdir(chunksDir, function (err, fileNames) { let destFileStream; if (err) { console.error("Problem listing chunks! " + err); failure(); } else { fileNames.sort(); destFileStream = fs.createWriteStream(fileDestination, {flags: "a"}); appendToStream(destFileStream, chunksDir, fileNames, 0, function () { rimraf(chunksDir, function (rimrafError) { if (rimrafError) { console.log("Problem deleting chunks dir! " + rimrafError); } }); success(); }, failure); } }); } function appendToStream(destStream, srcDir, srcFilesnames, index, success, failure) { if (index < srcFilesnames.length) { fs.createReadStream(srcDir + srcFilesnames[index]) .on("end", function () { appendToStream(destStream, srcDir, srcFilesnames, index + 1, success, failure); }) .on("error", function (error) { console.error("Problem appending chunk! " + error); destStream.end(); failure(); }) .pipe(destStream, {end: false}); } else { destStream.end(); success(); } } function getChunkFilename(index, count) { let digits = new String(count).length, zeros = new Array(digits + 1).join("0"); return (zeros + index).slice(-digits); } function sendToken(username, subject, text, url, res) { async.waterfall([ function(done) { crypto.randomBytes(20, function(err, buf) { token = buf.toString('hex'); tokenExpTime(); done(err, token, tokenExpire); }); }, function (token, tokenExpire, done) { myStat = "UPDATE UserLogin SET resetPasswordToken = ?, resetPasswordExpires = ? WHERE username = '" + username + "' "; myVal = [token, tokenExpire]; con_CS.query(myStat, myVal, function (err, rows) { if (err) { console.log(err); res.json({"error": true, "message": "Token Insert Fail !"}); } else { done(err, token); } }); }, function(token, done, err) { // Message object var message = { from: 'FTAA ', // sender info to: username, // Comma separated list of recipients subject: subject, // Subject of the message // plaintext body text: 'You are receiving this because you (or someone else) have requested ' + text + '\n\n' + 'Please click on the following link, or paste this into your browser to complete the process:\n\n' + url + token + '\n\n' + 'If you did not request this, please ignore this email.\n' }; smtpTrans.sendMail(message, function(error){ if(error){ console.log(error.message); res.json({"error": true, "message": "An unexpected error occurred !"}); } else { // res.send('Message sent successfully! Please check your email inbox.'); // console.log('Message sent successfully!'); // res.redirect('/login'); res.json({"error": false, "message": "Message sent successfully !"}); // alert('An e-mail has been sent to ' + req.body.username + ' with further instructions.'); } }); } ], function(err) { if (err) return next(err); // res.redirect('/forgot'); res.json({"error": true, "message": "An unexpected error occurred !"}); }); } #### Detailed explanation of the problem {describe the bug here}
  1. Set up Ubuntu server 16.04 with Node js v8.9.1
  2. Put all node js application with node module library onto Ubuntu server
  3. Go to node js application folder, run "node app.js" as an instance
  4. Fine-uploader works fine
  5. Use systemd to set up node js application as a service "service-A"
  6. Start "service-A", and fine-uploader refused to upload. It just said nothing, just error code "Exit-1", in journalctl -u service-A
Feature Request Just simply upload file when user select or drag and drop #### Feature request details {why is this feature important, not just for you, but for many others?}
Anson-Zhao commented 6 years ago
screen shot 2018-08-06 at 5 03 39 pm screen shot 2018-08-06 at 5 04 21 pm
rnicholus commented 6 years ago

Sorry, I can’t help you troubleshoot your server issues