3
cordova (cordova plugin file transfer)에서 nodeJS 서버로 가져온 사진을 업로드하려고합니다.cordova 파일 전송 플러그인에서 nodeJS 서버로 파일 업로드
function uploadToServer(pictureName, fileURI) {
var options = new FileUploadOptions();
options.fileKey = "file";
options.mimeType = "image/jpeg";
options.fileName = pictureName;
var ft = new FileTransfer();
ft.upload(fileURI, encodeURI(CONSTANTS.hosts.remoteSR),
function (res) {
console.log("Code = " + res.responseCode);
},
function (error) {
$log.debug(error)
alert("An error has occurred: Code = " + error.code);
},
options);
}
PS : fileURI 내 및 pictureName이 valide PARAMS 제대로 기능 withinother 테스트 여기 내 모바일 앱 코드입니다.
내 노드 JS 서버 코드 :
var express = require("express");
var multer = require('multer');
var app = express();
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads');
},
filename: function (req, file, callback) {
callback(null, file.fieldname + '-' + Date.now());
}
});
var upload = multer({ storage : storage}).single('userPhoto');
app.get('/',function(req,res){
res.sendFile(__dirname + "/index.html");
});
app.post('/api/photo',function(req,res){
upload(req,res,function(err) {
if(err) {
console.log(err)
return res.end("Error uploading file.");
}
res.end("File is uploaded");
});
});
app.listen(3000,function(){
console.log("Working on port 3000");
});
PS : 내가 다른 소스에서 업로드 할 때 업로드가 잘 작동된다. (예 : index.html 업로드 양식)
"코드 = 200"은 업로드 성공을 의미하지만 어떻게 든 업로드 된 파일을 찾지 못했습니다.
질문 : nodeJS
제대로 코르도바 파일 TRANSFERT의 pllugin을 연결하는 방법노드 버전 : 4.4.7 코르도바 버전 : 6.x의
나를 도왔습니다. 답을 공유해 주셔서 감사합니다. – Somename
제안 해 주셔서 대단히 감사합니다. 문제가 해결되었습니다. wav 파일을 모바일에서 nodejs로 보내려고 했으므로 nodejs 서버에 새로 업로드 된 파일에 다음과 같은 방법으로 추가 한 .wav ext가 없습니다. 콜백 (null, file.fieldname + '-'+ Date.now() + '.wav'); –