我是node.js的新手。在调用api时需要上传图片,图片以多部分表格数据的形式提供。
我怎样才能将图像细节作为回复?
答案 0 :(得分:1)
您可以使用multer.js作为正文解析器。它建立在busboy之上。 它有很好的记录。
答案 1 :(得分:0)
这个问题的答案如下:
fileupload.js:
client_id
查看:
var express = require("express"),
app = express();
// tell express to use the bodyParser middleware
// and set upload directory
app.use(express.bodyParser({ keepExtensions: true, uploadDir: "uploads" }));
app.engine('jade', require('jade').__express);
app.post("/upload", function (request, response) {
// request.files will contain the uploaded file(s),
// keyed by the input name (in this case, "file")
// show the uploaded file name
console.log("file name", request.files.file.name);
console.log("file path", request.files.file.path);
response.end("upload complete");
});
// render file upload form
app.get("/", function (request, response) {
response.render("upload_form.jade");
});
app.listen(3000);