2016-06-19 1 views
2

웹 브라우저에서 로컬 FS로 데이터를 보내야합니다. 데이터를 전송하기 위해 나는 vibed에 따라 뷰-JS component진동이있는 파일을 로컬 파일 시스템에로드하는 방법은 무엇입니까?

<file-upload class="my-file-uploader" name="myFile" id="myCustomId" action="/upload" multiple>Inside Slot Text</file-upload> 

내 서버 사이드를 사용하고 있습니다. 하지만 바이너리 데이터를 로컬 FS에 저장하는 방법을 모색 할 수는 없습니다. 내가 HTTPServerRequest .files를 사용해야하지만 그것을 사용하는 방법을 이해 할 수없는 그건

router.any("/upload", &upload);  
... 
void upload(HTTPServerRequest req, HTTPServerResponse res) 
{ 

} 

보인다. 사용자 업로드 작업은 여러 파일로 이루어집니다.

답변

3

Vibe.d Github repository에는 많은 예제가 있습니다.

예를 들어 작은 uploader이 있습니다.

router.post("/upload", &uploadFile); 

... 

void uploadFile(scope HTTPServerRequest req, scope HTTPServerResponse res) 
{ 
    auto pf = "file" in req.files; 
    enforce(pf !is null, "No file uploaded!"); 
    try moveFile(pf.tempPath, Path(".") ~ pf.filename); 
    catch (Exception e) { 
     logWarn("Failed to move file to destination folder: %s", e.msg); 
     logInfo("Performing copy+delete instead."); 
     copyFile(pf.tempPath, Path(".") ~ pf.filename); 
    } 

    res.writeBody("File uploaded!", "text/plain"); 
} 
내가 Vue.js에 대해 잘 모르는

하지만 it seems 그들은 너무 file를 사용합니다.

관련 문제