如何为我的网络应用获取类似 Gmail 的文件上传? [英] How can I get Gmail-like file uploads for my web app?

查看:12
本文介绍了如何为我的网络应用获取类似 Gmail 的文件上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的一个项目添加类似 gmail 的文件上传功能.有人可以帮我解决这个问题吗?

I want to add gmail-like file upload functionality for one of my projects. Can anybody help me with this?

我的应用程序是在 vb.net 中构建的.

My application is built in vb.net.

我将不胜感激任何形式的帮助或指导.

I would appreciate any kind of help or guidance.

谢谢

推荐答案

查看 SWFUpload,它本质上是一个 javascriptapi to flash 绝对优越的文件上传处理能力.在浏览器最终赶上之前最好的事情.

Check out SWFUpload, which is essentially a javascript api to flash's absolutely superior file upload handling capabilities. Best thing out there until the browsers finally catch up.

来自链接:

  • 在对话框中通过 ctrl/shift-selecting 一次上传多个文件
  • 所有事件的 Javascript 回调
  • 在上传开始前获取文件信息
  • 使用 XHTML 和 css 样式上传元素
  • 使用 HTML 上传文件时显示信息
  • 无需重新加载页面
  • 适用于所有支持 Flash 的平台/浏览器.
  • 如果 Flash 或javascript 不可用
  • 在上传开始前控制文件大小
  • 只在对话框中显示选择的文件类型
  • 上传队列,开始上传前删除/添加文件

演示

--iframe 上传 -----

----- iframe upload -----

首先,您希望在您的页面上有一个 iframe.这用于服务器通信.您稍后会隐藏它,但现在,让它保持可见.给那个 iframe 一个 name 属性,比如uploader"之类的.

To start, you want to have an iframe on your page. This is meant for server communication. You'll hide it later, but for now, keep it visible. Give that iframe a name attribute, like "uploader" or something.

现在,在您的表单中,将目标设置为 iframe 的名称,并将操作设置为您在服务器上接受文件上传的脚本(就像带有文件上传的普通表单一样).在该表单内添加一个带有文本添加文件"的链接.设置该链接以运行 javascript 函数,该函数将向表单添加新输入.这可以通过 DOM 完成,但我会推荐一个 JavaScript 库,例如 jquery.

Now, in your form, set the target to the iframe's name and the action to a script you have on the server that will accept a file upload (like a normal form with a file upload). Add a link inside that form with the text "Add File". Set that link to run a javascript function which will add a new input to the form. This can be done via the DOM, but I would recommend a javascript library like jquery.

将新文件输入添加到表单后,将该输入的模糊事件设置为将提交表单的 javascript 函数,然后定期检查它的输出.读取 iframe 可能会很棘手,但这是可能的.

Once the new file input is added to the form, set the blur event of that input to a javascript function that will submit the form and then check it periodically for output. Reading an iframe can be tricky, but it's possible.

让您的文件上传脚本输出完成".或上传完成时的文件名或其他内容.

Have your file upload script output a "Done." or a filename or something when the upload is complete.

每隔一秒左右检查一次,直到有内容为止.获得内容后,终止计时器并将文件输入替换为文件名(或文件上传")或其他任何内容.

Check it every second or so until there is content. Once you have content, kill your timer and replace the file input with the name of the file (or "File Uploaded") or whatever.

用 css 隐藏你的 iframe.

Hide your iframe with css.

这篇关于如何为我的网络应用获取类似 Gmail 的文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆