I'm using express with nodejs,
and i would like to use imgur to host pictures.
I have my access token, and I need to request this endpoint : "https://api.imgur.com/3/upload"
with the header : headers: {'Authorization': "bearer " + config.access_token_imgur, 'content-type': 'multipart/form-data'}
with the given picture.
When it comes to do it, the first problem is handling the picture : this is multipart and bodyparser can't. I tried multer, but it's always saving the picture, and i only want to get it, and post it to the endpoint, so, my goals is :
router.post("/upload",upload.single('file'), async (req,res)=>{
if(req.file){
var headers = {
headers: {"Authorization" : `Bearer ${config.access_token_imgur}`, 'content-type': 'multipart/form-data'}
};
var formData = new FormData();
//formData.append("image", req.file);
axios.post('https://api.imgur.com/3/upload', formData, headers).then((res)=>{
console.log(res);
console.log(res.body);
console.log(res.data);
}).catch((error)=>{
console.log(error);
})
//must get a picture from the parameters (how to handle ? )
//send it to https://api.imgur.com/3/upload with headers with post method
//handle response
}else{
res.status(500).json({success: false})
}
})
As you can see, i tried with multer, but i think this is not the good answer: How to handle the picture without saving ? (multipart), and send it to the endpoint ? (axios, request,...) Thanks