使用 HTML5 文件上传 API 进行断点续传 -

发布于 2024-11-27 00:40:20 字数 239 浏览 0 评论 0原文

我想用 Html5 实现可续传上传,除了确定要上传的文件与已部分上传的文件相同之外,一切似乎都有效。理想情况下,我会对文件进行一些客户端哈希,以生成唯一的 id - 但是我找不到它的任何工作实现,而且对于大文件来说它似乎太慢了(就像我正在处理的那样)。

接下来,我考虑使用文件的路径作为唯一标识符,但我没有看到任何从 API 获取它的方法。文件名,即使考虑每个用户的文件名也不能是唯一的,因为用户往往有通用的文​​件名。任何人都可以想到解决方案吗?

I want to implement resumable uploads with Html5, and everything seems to work, except identifying that the file to be uploaded is the same one already partially uploaded. Ideally, I would have some client side hashing of the file that generates unique id - however I could not find any working implementation of it and it seems too slow for large files (like I am dealing with).

Next, I thought about using the path to the file as the unique identifier, but I didn't see any way to get it from the API. file name, even considering file name per user can't be unique because users tend to have common names for files. Anyone can think of a solution for this?

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

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

发布评论

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

评论(2

a√萤火虫的光℡ 2024-12-04 00:40:20

我猜你最好的选择是一些简单的散列(MD5 在大文件上太慢而无用)。

另一种方法:按文件名命名上传(以及上传多个同名文件时的某种连续编号,例如 file-1、file-2、file-3),并检查已上传文件中的随机字节和本地文件。例如:

  1. 查找具有相同文件名的所有文件(不包括正在运行的数字编号)
  2. 将服务器中每 10 MB 的 10 个字节与本地文件进行比较,如果这些字节匹配,您可能有足够的信心认为这是正确的文件。

当然,这可能会导致错误的文件,但散列也可能会导致错误。

I guess you best choice is some simple hashing (MD5 is properly too slow on large files to useful).

An alternative: Name the uploads by the file name (and some kind of running numbering when multiple files with the same name is uploaded, e.g. file-1, file-2, file-3), and check random bytes in the already uploaded file and the local file. For example:

  1. Find all files with the same filename (excluding the running numerical numbering)
  2. Compare 10 bytes every 10 MB from the server with the local file, if these bytes match you may feel confident enough about this being the right file.

Of course this could lead to the wrong file, but so can hashing.

忆离笙 2024-12-04 00:40:20

正如 Mozilla Hacks 的如何恢复暂停或损坏的文件上传中提到的,也许您可以使用 IndexedDB 将文件存储在浏览器中,以便您可以在不需要用户的情况下恢复上传重新选择文件。

有关如何使用 IndexedDB 存储文件的教程,请参阅 在 IndexedDB 中存储图像和文件

As mentioned in How to resume a paused or broken file upload at Mozilla Hacks, perhaps you can store the file in the browser using IndexedDB so that you can resume the upload without needing the user to reselect the file.

For a tutorial on how to storing files with IndexedDB, see Storing images and files in IndexedDB.

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