ringojs 文件上传示例

发布于 2024-09-26 06:30:07 字数 34 浏览 1 评论 0原文

有人有使用ringojs 将文件上传到服务器的示例吗?

Does anyone have an example of uploading a file to the server using ringojs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南薇 2024-10-03 06:30:07

有一个简单的上传示例演示应用程序,但它将上传存储在内存中,这对于大多数应用程序来说不是一个好主意。要将上传保存到临时文件,您当前必须执行以下操作(这是上传演示操作的修改版本):

var fu = require("ringo/webapp/fileupload");

function upload(req) {
    if (fu.isFileUpload(req.contentType)) {
        var params = {};
        fu.parseFileUpload(req, params, req.charset, fu.TempFileFactory);
        return {
            status: 200,
            headers: {"Content-Type": "text/plain"},
            body: [params.file.name, " saved to ", params.file.tempfile]
        };
    }
    return Response.skin(module.resolve('skins/upload.txt'), {
        title: "File Upload"
    });
}

不幸的是,将上传保存到临时文件时存在一个错误,我刚刚修复了这个错误,所以您'必须手动使用当前的 git 快照或补丁文件 modules/ringo/webapp/fileupload.js

http://github.com/ringo/ringojs/commit/1793a815a9ca3ffde4aa5a07c656456969b504f9 >

我们还需要一些高级方法来为下一个版本执行此操作(例如设置 req.uploadTempDir 属性)。我将为此打开一个问题。

There's a simple upload example in the demo app, but it stores uploads in-memory which is not a good idea for most apps. To save uploads to a temporary file you'll currently have to do something like this (this is a modified version of the upload demo action):

var fu = require("ringo/webapp/fileupload");

function upload(req) {
    if (fu.isFileUpload(req.contentType)) {
        var params = {};
        fu.parseFileUpload(req, params, req.charset, fu.TempFileFactory);
        return {
            status: 200,
            headers: {"Content-Type": "text/plain"},
            body: [params.file.name, " saved to ", params.file.tempfile]
        };
    }
    return Response.skin(module.resolve('skins/upload.txt'), {
        title: "File Upload"
    });
}

Unfortunately, there was a bug with saving uploads to temp files that I just fixed, so you'll have to use a current git snapshot or patch file modules/ringo/webapp/fileupload.js manually:

http://github.com/ringo/ringojs/commit/1793a815a9ca3ffde4aa5a07c656456969b504f9

We also need some high level way of doing this for the next release (e.g. setting a req.uploadTempDir property). I'll open an issue for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文