thedgmbh / multi-rest Goto Github PK
View Code? Open in Web Editor NEWA middleware to handle multi-part request for restify
Home Page: https://www.npmjs.com/package/multi-rest
License: MIT License
A middleware to handle multi-part request for restify
Home Page: https://www.npmjs.com/package/multi-rest
License: MIT License
Hi,
I have the following code: (minimal version of read me file)
const restify = require('restify');
const Multi = require('multi-rest');
const uuidv4 = require('uuid/v4');
const server = restify.createServer();
server.use(restify.plugins.bodyParser());
const upload_disk = new Multi({
driver: {
type: 'local',
path: "./uploads/"
},
filename: (name) => `${name}_${uuidv4()}`,
filefields: {
image: {
type: 'picture',
thumbnail: {
width: 400,
height: 300
},
required: false,
extensions: ['png', 'jpg']
}
},
});
server.post('/v/1/file',
upload_disk,
(req, res) => res.send({
success: true,
files: req.files,
message: "file uploaded :)"
}));
server.listen(3010, () => console.log('%s listening at %s', server.name, server.url))
Whenever I try to upload an image, the app crashes and throws the following error:
events.js:182
throw er; // Unhandled 'error' event
^
Error: spawn convert ENOENT
at _errnoException (util.js:1026:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Request screen shot from postman:
Please advice if I am missing something.
Hi there,
The folder is not created "uploads" and I got File object in req.files.file, File path is "/var/folders/82/3s2yq3zj77l3xn1xvy9pgfx40000gn/T/upload_6bcd336e42b32122a8ed682e52ab".
I use restify.
var upload_disk = new Multi({
driver: {
type: 'local',
path: "uploads/"
},
filename: (name) => {
return uuid.v4();
},
filefields: {
image: {
type: 'file',
thumbnail: {
width: 400,
height: 300
},
required: false,
extensions: ['png', 'jpg']
}
}
});
server.post({ path: "photo", version }, upload_disk, this.savePhoto.bind(this))
savePhoto(req, res, next) {
console.log('FILE: ', req.files.file)
res.json(200, {})
return next()
}
By using the example code that you have given is throwing error.
TypeError: Cannot read property 'image' of undefined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.