2017-05-02 2 views
0

돛 js.In에서 새로운 코드입니다. 프런트 엔드에서 파일을 가져 오는 중입니다. 파일이 아래와 같이 오류를 표시하고 있습니다. 업로드 된 파일이 백엔드 폴더에 저장되어 있지 않습니다. 확인 후 내 코드.돛에 업로드 파일 js

upload: function(req, res) { 
    if (req.method === 'GET') 
     return res.json({ 'status': 'GET not allowed' }); 
    console.log("Get function is Excuted"); 

    var uploadFile = req.file('uploadFile'); 
    console.log(uploadFile); 

    uploadFile.upload({ dirname: './assets/images' },function onUploadComplete(err, files) { 


     if (err) { 
      console.log(" Upload file is error"); 
      return res.serverError(err); 

     } 
     // IF ERROR Return and send 500 error with error 

    console.log(files); 
     res.json({ status: 200, file: files }); 
    }); 
}, 

오류 코드 :

I am getting error in sails js console is this.

HTML 코드 : 내 코드에서

내가 어떤 업로드 파일의 예제를 제공하기 위해 저번를 확인하시기 바랍니다 작은 문제에 직면하고있다 돛에 js.

+0

이 링크가 보이셨습니까? http://sailsjs.com/documentation/concepts/file-uploads? 프런트 엔드 DropZonesJS http://www.dropzonejs.com/#configuration-options에서도 사용할 수 있습니다. – Makah

답변

0

업로드 양식에 올바른 인코딩 유형을 사용하지 않는 것이 가장 좋습니다. 그 여기 https://www.w3schools.com/tags/att_form_enctype.asp

에 대한 자세한 내용을 참조하십시오 여기에 완성도를 들어

<form action="/file/upload" enctype="multipart/form-data" method="post"> 
    <input type="file" name="file"> 
</form> 

나는 또한 내가 로컬 테스트를 가지고 돛 파일 업로드 컨트롤러의 기본 동작하는 예제를 포함 한 간단한 양식의 예입니다.

upload : function (req, res) { 
    req.file('file').upload({ 
    // don't allow the total upload size to exceed ~100MB 
    maxBytes: 100000000, 
    // set the directory 
    dirname: '../../assets/images' 
    },function (err, uploadedFile) { 
    // if error negotiate 
    if (err) return res.negotiate(err); 
    // logging the filename 
    console.log(uploadedFile.filename); 
    // send ok response 
    return res.ok(); 
    } 
}