如何用vibed将文件加载到本地文件系统? [英] How to load files to local file system with vibed?
本文介绍了如何用vibed将文件加载到本地文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将数据从Web浏览器发送到本地FS.为了发送数据,我使用的是Vue-JS 组件
I need to send data from web-browser to local FS. For sending data I am using Vue-JS component
<file-upload class="my-file-uploader" name="myFile" id="myCustomId" action="/upload" multiple>Inside Slot Text</file-upload>
我的服务器端基于vibed.但是我找不到如何将二进制数据保存到本地FS的示例.
My server side based on vibed. But I can't find example how to save binary data to local FS.
router.any("/upload", &upload);
...
void upload(HTTPServerRequest req, HTTPServerResponse res)
{
}
似乎我应该使用 HTTPServerRequest .files,但是我可以不知道如何使用它.用户上载需要多个文件.
It's seems that I should use HTTPServerRequest.files But I can't understand how to use it. User upload takes is multiple files.
推荐答案
You can find a lot of examples within the Vibe.d Github repository.
例如,有一个小的上传器.
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");
}
I don't know much about Vue.js, but it seems they use file
too.
这篇关于如何用vibed将文件加载到本地文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文