3

하나의 파일을 업로드하기 위해 노드 앱에 다중 노드 노드 모듈을 사용하고있었습니다. 자, 같은 multiparty 모듈을 사용하여 여러 파일을 업로드하고 싶습니다. 나는 봤지만 어떤 해결책을 찾을 수 없습니다. link에있는 '멀 터'모듈을 찾았습니다. 기존 모듈에 문제가 있습니다. 그럼, 'multiparty'를 사용하여 파일을 업로드 할 수있는 방법이 있습니까?노드에 "multiparty"모듈을 사용하여 여러 파일을 업로드 할 수 있습니까?

답변

0

request 모듈을 권장합니다. 문제 해결에 도움이 될 것입니다.

+1

감사합니다. @David, 같은 것을 사용하는 예제가 도움이 될 것입니다. – Worker

2

많은 시도가 실패하고 실험이 해답을 얻은 후 클라이언트에서 서버로 양식 객체를 보냈습니다. 서버 측에서 아래의 코드를 확인하십시오.

app.post('/multiFileUpload', function(req, res) { 

     var singleFile;  
     var form = new multiparty.Form(); 

     form.parse(req, function(err, fields, files){  
      var fileArry=files.uploadFiles;     
        if(fileArry == null){ 
         res.send('No files found to upload.'); 
          return; 
        } 

         for(i=0; i<fileArry.length; i++) 
         { 
          newPath='./uploads/'; 
          singleFile=fileArry[i]; 
          newPath+=singleFile.originalFilename; 
          readAndWriteFile(singleFile,newPath);      
         } 
         res.send("File uploaded to: " + newPath); 
       }); 

    }); 

    function readAndWriteFile(singleFile , newPath){ 

     fs.readFile(singleFile.path, (err, data)=>{ 
      fs.writeFile(newPath, data, (err)=>{                             
        console.log("File uploaded to :"+newPath); 
       }); 
     }); 
    } 
+0

나는 당신과 똑같이했고 단지 마지막 파일 만 업로드했다. 유일한 차이점은 For 내부에서 readFile과 fs.writeFile을 수행했다는 것입니다. 왜 그것이 작동하지 않았는지 나는 모른다. Anywa 고맙습니다! : D @ 워커 – Despertaweb