2016-10-06 4 views
0

다음은 이미지 파일과 TODO 작업 및 설명에 대한 정보를 보내려는 HTML 페이지입니다. http://pastebin.com/W9TVy4Annode.js에서 다중 부분 데이터를 보내고받는 방법은 무엇입니까?

form.on('part', (part) => { 
if (part.filename) { 
    let imagePath = '' 
    let privateIndex // will hold the index for private images 
    let index // will hold the index for the public images 
    let file = '' 

    part.setEncoding('binary') 
    part.on('data', (data) => { 
    file += data 
    }) 
    part.on('end',() => { 

    if (isPrivate) { 
     // handle a private image 
    } else { 
     // handle a public image 

    } 
    if (!fs.existsSync(imagePath)) { 
     fs.mkdir(imagePath) // create the folder for the image 
    } 

    imagePath += isPrivate ? privateIndex + '.jpg' : index + '.jpg' // add the image name to complete the path for saving 

    fs.writeFile(imagePath, file, 'ascii', (err) => { 
     // stuff 
     } 
    }) 

    callback(part.filename) 
    }) 

나는 위와 같이 Node.js를에서 다자간를 사용하여 파일을받을 수 있지만 나는 내 인생에 대한 TODO 작업의 설명과 이름에 대한 정보를 수신 할 수있는 방법을 알고있다.

누구나 내가 할 수있는 바보 같은 실수를 지적 할 수 있습니까?

답변

0

좋아, 나는 방법을 알아 냈어. 그리고 양식을 파싱 할 때 fieldsfiles 속성을 읽는 것이다.

let form = new multiparty.Form() 
form.parse(req, (err, fields, files) => { 
    console.log(fields) 
}) 

필드는 속성 이름을 키로 가지는 객체이며 값은 값입니다. 결과는

{ todoname: [ 'Post the answer' ], tododesc: [ 'Post the answer you figured out on your StackOverflow question' ] } 
입니다.
관련 문제