I'm using this code to send a file to my NODE server:
this code returns error: ResponseError: request completed with error, status code: 500
However no file is saved in the server.
It needs to emulate POSTMAN behaviour like the picture below:
Can the reason for this error be the NODE JS code?, cos' it only accept one file:
Upload File:
Sub EnviarArchivo(posturl As String)
Dim j As HttpJob
Dim NameValues As Map
NameValues.Initialize
j.Initialize("", Me)
Dim fd As MultipartFileData
fd.Initialize
fd.KeyName = "profile"
fd.Dir = File.DirAssets
fd.FileName = "1.jpg"
fd.ContentType = "image/jpg"
Log("Archivo:" & fd.Dir & "/" & fd.FileName)
NameValues.Put("profile",fd.Dir & "/" & fd.FileName)
j.PostMultipart(posturl, NameValues, Array(fd))
' j.GetRequest.SetHeader("profile", fd.Dir & "/" & fd.FileName) ' or whatever you need to set. Do it here
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
j.Release
End Sub
However no file is saved in the server.
It needs to emulate POSTMAN behaviour like the picture below:
Can the reason for this error be the NODE JS code?, cos' it only accept one file:
Server Code:
const express = require('express');
const multer = require('multer');
const path = require("path");
const router = express.Router();
const moduloSQL = require('C:/AppsV2/sqlConfig')
const sql = require('mssql')
// https://www.youtube.com/watch?v=jn3tYh2QQ-g
// Compartir la carpeta:
// app.use('/profile', express.static('upload/images'));
const storage = multer.diskStorage({
destination: './upload/images',
filename: (req, file, cb) => {
return cb(null, `${file.fieldname}_${Date.now()}${path.extname(file.originalname)}`)
}
})
// FileSize en es bytes
const upload = multer({
storage: storage,
limits: {
fileSize: 30000
}
});
router.post('/',upload.single('profile'),(req, res) => {
//console.log("Parametro req.body.file:" & req.file.filename);
res.json({
success: 1,
profile_url: `http://localhost:4000/profile/${req.file.filename}`
})
});
module.exports = router;