노드 서버를 만들어 파일을 업로드 한 다음 노드를 사용하는 스토리지 서버로 보냅니다.요청 모듈을 통한 노드 JS 파일 전송
var formData = {
my_field: 'my_value',
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
};
request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});
내 문제는 내가 스토리지 서버에 파일을 작성하려고 할 때이 내용에 텍스트 파일을 생성하는 것입니다 [객체 : 내가 양식 - 데이터 모듈 페이지에 설명이 방법을 사용하고이 작업을 수행하려면 목적]. 여기
내 코드입니다 :main.js
var form = new formData();
form = {
'oldFileName': oldName,
'newFileName': newName,
'file': fs.createReadStream(FILEPATH),
};
request.post({url:'http://127.0.0.1:9001/upload', form: form}, function(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
});
storage.js
app.post('/upload', function(req,res){
//Filenames are displayed without problem
console.log(req.body.newFileName);
console.log(req.body.oldFileName);
fs.writeFile('./testing/' + req.body.newFileName, req.body.file, function(err) {
if(err) {
return console.log(err);
}
})
내가 정말 뭔가를 분명 누락 확신 해요,하지만 난 것 같다 캔트 그것을 작동 시키십시오.
'storage.js'에서'multipart/form-data'를 받아들이려면'multer' 또는 유사한 라이브러리를 사용해야한다고 생각합니다. –
나는 그것을 시도했지만 (미안했을 것입니다),'multer'가 나타나지 않았습니다. 구성된 양식의 파일을 인식하는 방법 –