Tag: 强大

用restify清理file upload后的临时文件

我正在用restify构build节点存储服务器。 我正在通过restify.bodyParser处理上传,其中引擎盖下使用formidable 。 在默认情况下,强大的商店文件在os.tmpDir() ,我需要将其更改为其他文件夹,所以我通过restify.bodyParser({uploadDir: '/path/to/new/tmp'}) 。 问题在于,即使在完成处理请求之后,这些临时文件仍保存在tmp目录中。 我已经看到了这个问题( 上传后处理临时文件 ),假设刚刚删除后处理它的tmp文件。 我的问题是,你是否需要总是手动删除文件? 即使使用默认的os.tmpDir()目录? 默认系统tmp文件夹如何工作? 它有时会冲洗吗?

Node.js强大的重命名上传的文件

试图完成“Node初学者书”这本书,最后我需要的是实现修改一个请求处理程序,它显示一个图像,在用户上传后重命名,我使用node-formidable和fs模块。 var fs = require("fs"), formidable = require("formidable"); function upload (resp, req) { var form = new formidable.IncomingForm(); form.parse(req, function (error, fields, files) { /* This is the part that doesn't work on Windows */ fs.rename(files.upload.path, "/tmp/test.png", function (error) { if (error) { fs.unlink("/tmp/test.png"); fs.rename(files.upload.path, "/tmp/test.png"); } }); resp.writeHead(200, {"Content-Type":"text/html"}); resp.write("Received image:<br/>"); resp.write("<img src=/show />"); […]

强大的多file upload – ENOENT,没有这样的文件或目录

我知道这个问题已经被问到,但是我的思想已经被我无法得到这个工作所吹。 我正在尝试使用以下代码将多个图像上传到我的服务器: var formidable = require('formidable'); var fs = require('fs'); … router.post('/add_images/:showcase_id', function(req, res){ if(!admin(req, res)) return; var form = new formidable.IncomingForm(), files = []; form.uploadDir = global.__project_dirname+"/tmp"; form.on('file', function(field, file) { console.log(file); file.image_id = global.s4()+global.s4(); file.endPath = "/img/"+file.image_id+"."+file.type.replace("image/",""); files.push({field:field, file:file}); }); form.on('end', function() { console.log('done'); console.log(files); db.get("SOME SQL", function(err, image_number){ if(err){ console.log(err); } var […]

npm install formidable在节点0.10中不起作用

我正在做“节点初学者手册”中的教程,由于版本错误,我无法安装formidable的工具。 这是错误。 我似乎得到这个错误,或不使用sudo和@latest 。 npm install formidable@latest npm http GET https://registry.npmjs.org/formidable npm http 304 https://registry.npmjs.org/formidable npm WARN engine formidable@1.0.13: wanted: {"node":"<0.9.0"} (current: {"node":"v0.10.0","npm":"1.2.14"})

如何得到http请求file upload的响应中止?

我打算用express来上传一个使用nodejs的文件。 我看到bodyParser完成了这项工作 app.use(express.bodyParser({"limit": '2mb'})); 但是,如果我想限制请求的大小,我发现它不会取消上传。 客户端不断发送数据。 所以我写了这个中间件: app.use(function (err, req, res, next) { if(err.status == 413){ req.destroy(); return res.json({ "status": 413, "message": err },413); }else next(err); }); 它工作,取消上传,但客户端不会(或忽略)回应! 我认为这可能是一个http协议的行为,所以任何帮助表示赞赏。

Express socket.io强大的意思。坚持如何在forms上进行整合

我正在做一个吝啬的 server.js 'use strict'; /** * Module dependencies. */ var express = require('express'), fs = require('fs'), passport = require('passport'), logger = require('mean-logger'); /** * Main application entry file. * Please note that the order of loading is important. */ //Load configurations //Set the node enviornment variable if not set before process.env.NODE_ENV = process.env.NODE_ENV || 'development'; […]

如何一次上传多个文件,使用强大的expression方式

我正在尝试使用强大的模块上传文件。 但是,当我select多个file upload,只有第一个上传。 我是节点的新手。 这里是我的上传function exports.uploadPhotos = function(req, res) { console.log("upload received"); var form = new formidable.IncomingForm(); form.multiples = true; form.parse(req, function(err, fields, files) { res.status(200, { 'content-type': 'text/plain' }); res.end('received upload:\n\n'); res.end(util.inspect({ fields: fields, files: files })); }); form.on('end', function(fields, files) { /* Temporary location of our uploaded file */ var temp_path = this.openedFiles[0].path; […]

用sizelimit上传文件节点js

我做了一个简单的HTML表单来上传图片。 我正在尝试使用强大的中间件来处理我的形象。 var form = new formidable.IncomingForm(); var filename = req.body.pid + ".jpg"; //Formidable uploads to operating systems tmp dir by default form.uploadDir = "/src/main/images"; //set upload directory form.keepExtensions = true; //keep file extension form.on('progress', function(bytesReceived, bytesExpected) { if (bytesReceived > MAX_UPLOAD_SIZE) { console.log('### ERROR: FILE TOO LARGE'); } }); form.parse(req, function(err, fields, files) { […]

NodeJS图像上传成功,但Resize不能使用GraphicsMagick

我正在尝试调整上传的图片的大小。 我已经testing了差不多的方法,我可以在互联网上find,但没有一个似乎工作。 我能够上传图像到服务器的文件夹,但它仍然保持完整的图像大小。 我错过了什么? var formidable = require('formidable'), path = require('path'), fs = require('fs'), gm = require('gm'); //handles image upload exports.image = function (req, res) { var form = new formidable.IncomingForm(); form.parse(req, function (err, fields, files) { var file = files.file; var tempPath = file.path; var rename = makeid(); var targetPath = path.resolve('./public/assets/images/upload/'+ file.name ); […]

os.tmpDir()被弃用 – 节点和强大

我使用节点版本7.2.0和强大的版本1.0.17进行file upload。 在更新到节点版本7.2.0之后,现在在上传文件时出现以下错误: (node:3376)DeprecationWarning:os.tmpDir()已被弃用。 使用os.tmpdir()代替。 我不使用form.uploadDir的deafult,但一些自定义path。 我将如何解决这个错误? 非常感谢。