이 코드가 있습니다NodeJS에서 파일 업로드를 처리하는 방법은 무엇입니까?
http.createServer(function (req, res) {
if (req.method.toLowerCase() === "post") {
res.writeHead(200);
req.on('data', function (data) {
console.log(data.toString());
});
res.end();
}
}).listen(8006);
내가 curl http://localhost:8006/upload -X POST -F [email protected]
같은 컬 명령을 사용하여 파일을 업로드하려고하면, 나는 파일의 이름과 인쇄 파일의 내용을 얻을 수 있습니다을이에있는 경우는 다음과 같습니다 :
------------------------------5d02ba973600
Content-Disposition: form-data; name="file"; filename="filetoupload.txt"
Content-Type: text/plain
<!-- start slipsum code -->
Do you see any Teletubbies in here? Do you see a slender
plastic tag clipped to my shirt with my name printed on
it? Do you see a little Asian child with a blank expression
on his face sitting outside on a mechanical helicopter that
shakes when you put quarters in it? No? Well, that's what
you see at a toy store. And you must think you're in a
toy store, because you're here shopping for an infant
named Jeb.
<!-- end slipsum code -->
------------------------------5d02ba973600--
이제 질문은 파일 이름과 파일의 내용을 알아볼 수있는 좋은 방법이 있습니까? 아니면 위의 내용을 추출하기 위해 일종의 정규 표현식을 사용해야합니까?
express와 같은 타사 모듈을 사용하지 않고이 작업을 수행하고 싶습니다. 먼저 'bodyParser()가 모든 파일을 디스크에 저장 한 다음 강력한 모듈과 같은 다른 모듈에 저장하므로 디스크에서 읽으려는 경우, 먼저 파일을 디스크에 저장하지 않고 Rackspace CloudFiles로 파일을 직접 파이프하는 작업을하려고합니다.
그것은 거대한 코드베이스이고 나는 그것을 이해하려고 시간이 오래 걸릴 것 같아요 ...하지만 아무도 다른 응답하지 않을 때까지가있어 내가 할 수있는 최선 ... –
양식 업로드를 처리하는 것이 본질적으로 매우 어려운 과정이며 특별한 경우와 오류 조건을 모두 처리 할 수 있어야한다고 생각할 수 있습니다. 나는한다. "이걸 더 좋고 더 간단하게 할 수있다"는 생각의 함정에 빠지기 쉽습니다. 때로는 그렇게하는 사람들이 옳습니다. 훨씬 더 자주 그들은 틀렸어. – ebohlman