如何使用 vibed 将文件加载到本地文件系统?

How to load files to local file system with vibed?

我需要将数据从网络浏览器发送到本地 FS。为了发送数据,我使用的是 Vue-JS component

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

我的服务器端基于 vibed。但是我找不到如何将二进制数据保存到本地 FS 的示例。

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

}

看来我应该使用HTTPServerRequest.files 但我不明白如何使用它。用户上传需要的是多个文件。

您可以在 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