send.js
var buffer = await new Promise( (rs,rj) =>{
request({
url : 'domain.com/img.jpeg',
method : 'get',
encoding: null
},function(error, response, body){
rs(body)
})
})
request({
method : 'POST',
url : 'http://localhost:5050/upload', //
port : 443,
headers: {
'Content-type': 'multipart/form-data'
},
formData : {
file_name : 'name.jpg',
file : buffer
}
})
EXPRESS.js
const express = require("express")
const app = express()
const multer = require('multer')
const upload = multer()
const fs = require('fs')
const imageStorage = multer.memoryStorage()
const imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: 15000000
}
})
app.post('/upload',imageUpload.single('file'),async function(req, res){
console.log(req.file)
console.log(req.body)
res.send(200)
})
const port = 5050
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Mọi người giúp em với ạ express toàn xuất
undefined
[Object: null prototype] { file_name: 'name.jpg' }