是否可以仅使用JavaScript进行可靠的文件上传 [英] Is robust javascript-only upload of file possible

查看:83
本文介绍了是否可以仅使用JavaScript进行可靠的文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一种可靠的方式来上传文件.这意味着我希望能够处理中断,错误和暂停.

I want a robust way to upload a file. That means that I want to be able to handle interruptions, error and pauses.

所以我的问题是:仅在客户端上使用javascript可能会发生以下情况.

如果是这样,我想要指向库,教程,书籍或实现的指针. 如果不是,我想解释一下为什么不可能.

If so I would like pointers to libraries, tutorials, books or implementations. If not I would like an explanation to why it's not possible.

场景:

  • 打开大文件
  • 将其拆分为多个部分

我想为每个部分

  • 创建校验和并追加到数据
  • 将数据发布到服务器(服务器将检查数据是否正确上传)
  • 检查服务器上的网页以查看上传是否正常
  • 如果是,如果没有重试,请上传下一部分
  • Create checksum and append to data
  • Post data to server (the server would check if data uploaded correctly)
  • Check a web page on server to see if upload is ok
  • If yes upload next part if no retry

假设所有发往服务器的信息都带有相关的元数据( sessionid和whatnot ).

Assume all posts to server is accompanied by relevant meta data (sessionid and whatnot).

推荐答案

否.您可以通过一定程度的黑客攻击,使用AJAX开始文件上传,在这种情况下,能够告诉您何时完成上传.就是这样.

No. You can, through a certain amount of hackery, begin a file upload with AJAX, in which case you'll be able to tell when it's finished uploading. That's it.

出于安全原因,JavaScript无法直接访问访问者计算机上的文件.在脚本中最多可以看到的是文件名.

JavaScript does not have any direct access to files on the visitor's computer for security reasons. The most you'll be able to see from within your script is the filename.

这篇关于是否可以仅使用JavaScript进行可靠的文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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