@post(%27/files%27, {
responses: {
%27204%27: {
description: %27Uploaded%27,
},
},
})
async fileUpload(
@requestBody.file()
request: Request,
@inject(RestBindings.Http.RESPONSE) response: Response,
): Promise<string> {
console.log(request.file.filename);
const storage = multer.diskStorage({
destination: %27./public/uploads%27,
filename: function (req, file, cb) {
cb(null, %27image-%27 + Date.now() + path.extname(file.filename));
},
});
const upload = multer({storage: storage}).single(%27image%27);
upload(request, response, (err: unknown) => {
if (err) console.log(err);
else {
console.log(request.file.filename);
}
});
return %27Yes%27;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter