So , to start you will need to use a static folder you can do this with express, if you do not have the module still use this
npm init -y
npm i -S [email protected]
Declare the static folder
const express = require('express')
, app = express();
app.use(express.static('caminho_da_pasta'));
app.listen(numero_da_porta, () => console.log('App na porta numero_da_porta'));
Now to use the multer:
const multer = require('multer');
const upload = multer({ dest: 'pasta_de_rececao/' });
//upload com um POST
app.post('caminho_dentro_da_pasta_estatica', upload.single('nome_da_tag'),
(req, res) => res.send('Sucesso'));
upload.single('name_da_tag') indicates that we are interested in the data sent with the name file, the same name used by
<input type="file" name="nome_da_tag">
If you succeed your file will be inside the specified folder only the file name will be different from the original name to have the original name with the extension and need to specify a Storage with the multer also
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'pasta_de_rececao/');
},
filename: function (req, file, cb) {
cb(null, `${file.fieldname} + '-' +${path.extname(file.originalname)`})
}
});
//e em vez de passar a pasta_de_rececao como argumento , passamos a storage
const upload = multer({ storage });
just then pick up the image path + the image name and send with the Imgur module
var imgur = require('imgur');
imgur.setAPIUrl('https://api.imgur.com/');
imgur.uploadFile('/caminho/da/imagem.png')
.then(function (json) {
console.log(json.data.link);
})
.catch(function (err) {
console.error(err.message);
});
source:Mgur
I hope it helps
So as I said in the reply, just indicate the relative path of the file and go through Imgur https://www.npmjs.com/package/imgur#uploading-files-globbing-supported maybe the part of sending pro Imgur is clearer here I edited my answer if you think that
– ScrapBench