Hi,
I am trying to upload the image file to the File document using rest API in NodeJS. For that what is the formData example. Kindly let me know. I am getting an error like
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
Here is my code:
app.post('/api/getPhoto', upload.single('file'), function (req, res) {
const file = req.file;
const fileContent = fs.readFileSync(file.path);
const params = {
filedata: fileContent.toString('base64'),
filename: file.filename,
is_private: 1,
};
var options = {
method: 'POST',
url: 'https://pranera.erpnext.com/api/resource/upload_file/',
headers:
{
'Authorization': "token "+ "xxxxxxxx" + ":" + "xxxxxxxxxx",
'Accept': 'application/json' ,
'Content-Type': 'multipart/form-data'
},
formData: params
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
if (response.statusCode == 200){
console.log("body",body);
data = {
message : "Photo received"
}
res.send( {'data': data});
}
});
});