2
I have an API I made based on a tutorial, where I can upload files:
Server.js
var express = require('express')
, app = express()
, bodyParser = require('body-parser')
, multiparty = require('connect-multiparty');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 8080;
var router = express.Router();
app.use('/api', router);
/*insira as rotas aqui */
router.route('/upload')
.post(multiparty(), require('./controllers/uploads'));
app.listen(port);
console.log('conectado a porta ' + port);
Upload.js
var fs = require('fs');
module.exports = function(req, res){
res.setHeader("Access-Control-Allow-Origin", "*");
var arquivo = req.files.file;
var temporario = req.files.file.path;
var novo = './uploads/' + req.files.file.name;
fs.rename(temporario, novo, function(err){
if(err){
res.status(500).json({error: err})
}
res.json({message: "enviado com sucesso.", file: novo});
})
}
I can successfully upload it to an Api project folder, but what about downloading the uploads I do? How would that be? some example?