我需要从网络浏览器发送数据到本地FS。用于发送数据,我使用Vue-JS 组件。
<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,但是我不知道如何使用它。用户上传是多个文件。
发布于 2016-06-19 20:32:51
您可以在Vibe.d Github储存库中找到许多示例。
例如,有一个小上传器。
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不太了解,但是看起来他们也使用file。
https://stackoverflow.com/questions/37911439
复制相似问题