2016-12-17 7 views
0

나는 분명히 Vibe.d를 처음 사용하므로 분명히 뭔가 빠져있다면 용서해주십시오.웹 프레임 워크를 사용하여 vibe.d에 파일을 업로드하는 방법

웹 프레임 워크를 사용하여 Vibe.d에 파일을 업로드하고 싶습니다. 그러나 'D Web Development'라는 책을 포함한 모든 예제는 웹 프레임 워크를 사용하지 않습니다. 내 웹 프레임 워크가 아닌 예제를 앱에 삽입하면 충돌이 발생합니다. 파일 업로드라는 하나의 기능 만 위해 웹 프레임 워크를 포기해야한다면 당황 할 것입니다.

Vibe.d 문서는 좋은 시도이며 감사합니다. 그러나 지금까지는 오히려 드문 드문 드문 예가 몇 가지 있습니다.

shared static this() 
{ 
    auto router = new URLRouter; 
    router.post("/upload", &upload); 
    router.registerWebInterface(new WebApp); 
    //router.get("/", staticRedirect("/index.html")); 
    //router.get("/ws", handleWebSockets(&handleWebSocketConnection)); 
    router.get("*", serveStaticFiles("public/")); 

    auto settings = new HTTPServerSettings; 
    settings.port = 8080; 
    settings.bindAddresses = ["::1", "127.0.0.1"]; 
    listenHTTP(settings, router); 

    conn = connectMongoDB("127.0.0.1"); 
    appStore = new WebAppStore; 
} 

void upload(HTTPServerRequest req, HTTPServerResponse res) 
{ 
    auto f = "filename" in req.files; 
    try 
    { 
     moveFile(f.tempPath, Path("./public/uploaded/images") ~ f.filename); 
    } 
    catch(Exception e) 
    { 
     copyFile(f.tempPath, Path("./public/uploaded/images") ~ f.filename); 
    } 
    res.redirect("/uploaded"); 
} 

나는 여전히 웹 프레임 워크를 사용하여 HTTPServerRequest.files에 액세스 할 수 있습니다

여기 내 코드의 일부 조각인가? 방법? 아니면 여전히 필요합니까? HTTPServerRequest.files를 사용하지 않고 다른 방법이 있습니까?

고맙습니다.

+0

당신이 볼나요 양식 포스트를 처리하기 위해 사용? https://github.com/rejectedsoftware/vibe.d/tree/master/examples/uploader – Bauss

+1

check http://stackoverflow.com/questions/37911439/how-to-load-files-to-local-file-system -with-vibed – Qurashi

+0

안녕하세요 Bauss, Github 예제는 웹 프레임 워크를 사용하지 않고 HTTPServerRequest.files를 사용하고 있습니다. 웹 프레임 워크는 양식을 통해 데이터를 전달하며 HTTPServerRequest.files에 액세스 할 수 없습니다. –

답변

0

는 웹 애플리케이션 클래스 내부의 업로드 기능을 넣고 form(action="/upload", method ="post")

class WebApp { 

    addUpload(HTTPServerRequest req, ...) 
    { 
     auto file = file in req.files; 
     ... 
    } 
} 
+0

@aberba에 감사드립니다. 나는 실제로 그것을 발견했지만 내 질문으로 돌아가는 것을 잊어 버렸다. 도와 주셔서 감사합니다. –