RESTful方式的文件上传

发布于 2024-12-29 12:44:56 字数 149 浏览 2 评论 0原文

我想使用 openrasta 以 RESTful 方式实现文件上传,但无法找到正确的方法来实现它。我能找到的方法很少,例如使用 Ajax 文件上传或使用 Iframe。

任何人都可以建议任何方法来做到这一点,或者为我提供一些我可以参考的资源。

提前致谢

I want to implement file upload in RESTful way using openrasta but not able to find proper way to implement it.There are few ways like using Ajax file upload or using Iframe which i could find.

Can anybody suggest any way of doing this or provide me some resources from where i can refer.

Thanks in advance

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

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

发布评论

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

评论(1

染柒℉ 2025-01-05 12:44:56

在我看来,你正在尝试在 html 环境中构建文件上传。

你有两个选择。

使用 HTML 表单上传文件。

<form enctype="multipart/form-data" action="/files" method="post">
  <fieldset>
    <input type="file" name="filename" />
    <input type="submit" />
  </fieldset>
</form>

您可以非常轻松地将其映射到 OR 中。您的处理程序将如下所示:

public object Post(IFile filename) { /* do something with the file */ }

您无法使用进度条执行基于 ajax 的文件上传,因为纯 xmlhttprequest 中无法操作二进制文件。如果您在后台使用 flash/silverlight 控件,则只需确保将文件的内容发布到 /files ,如前面的示例所示,这是最简单的方式是使用 application/octet-stram 的 Content-Type http 标头发送内容,并且相同的处理程序代码将正常工作。

It seems to me you're trying to build file uploading in an html environment.

You have two choices.

Use an HTML form to upload the file.

<form enctype="multipart/form-data" action="/files" method="post">
  <fieldset>
    <input type="file" name="filename" />
    <input type="submit" />
  </fieldset>
</form>

You can map that in OR very easily. Your handler would look like this:

public object Post(IFile filename) { /* do something with the file */ }

You can't do ajax-based file upload with progress bars as there is no way in pure xmlhttprequest to manipulate binary files. If you go down the route of using a flash / silverlight control behind the scene, you'll just need to make sure you post the content of the file to /files as in the previous example, the easiest way being to send the content with a Content-Type http header of application/octet-stram, and the same handler code will just work.

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