html在分块中加入文字,重新加入分块的HTML 5上传(Rejoining chunked HTML 5 uploads)

重新加入分块的HTML 5上传(Rejoining chunked HTML 5 uploads)

我们从头开始使用文件api构建了一个HTML5上传器,没有外部库,它工作正常,直到我们尝试上传> 150MB的文件。 此时我们意识到我们需要将文件上传为块。

事物的Javascript方面正在由正在拆分文件和上传的其他人进行排序。 我正在研究PHP方面的事情,需要知道我需要了解的是如何重新加入这些块。

我是否需要修改每个块的标头?

在等待下一个时,我应该如何排队?

我们这么做了很长的路吗?

We've built a HTML5 uploader using file api from scratch with no outside libraries and it was working fine until we tried to upload a file > 150MB. At this point we realised we need to upload the file as chunks.

The Javascript side of things is being sorted by someone else who is splitting the files and and uploading. I'm working on the PHP side of things and need to know what I need to be looking at to work out how to rejoin these chunks.

Do I need to modify the headers of each chunk?

How should I queue chunks while waiting for the next one?

Are we doing this the long way?

原文:https://stackoverflow.com/questions/12857320

更新时间:2019-12-19 05:57

最满意答案

在我看来,你需要与gui一起讨论javascript方面,或者至少从他那里获取完成的脚本并查看代码,很可能块号将在请求的标题之一中发送。

由于你将在不同的PHP脚本中接收块我建议你将它们存储在数据库或文件系统中,因为你需要添加块号,如果你真的想要去文件系统,那么文件系统会更难一些路径我建议你将它们存储在一个文件夹中,该文件夹的名称和文件名为0 ... chunk_count-1作为该文件夹中的文件。

您还应该通过标题收到块的总数,并在上传后比较您有多少块。 当你拥有所有块时,只需按照块ID的顺序组装它们。 如果您使用文件系统,所有文件实际上都已完全写入(通常如果总大小与原始大小匹配),则应该小心。 数据库使这更加简单,因为当您拥有所有数据时,可以在其中插入一行。

确保所有文件完全写入的文件系统方法的解决方法是将它们写入不同的文件夹,并在完成写入后将它们移动到目标文件夹。两个文件夹应位于同一文件系统上,因此移动不会生成副本+删除。

Looks to me like you need to talk with the gui doing the javascript side or at least get the finished scripts from him and take a look at the code, quite likely the chunk number will be sent in the one of headers for the request.

Since you'll be receiving chunks in different php scripts I suggest you store them in the database or in the filesystem, it will be a bit harder with the filesystem as you need to also add the chunk number, if you really wanna go the filesystem path I suggest you store them in a folder having the file name as it's name and the chunks as 0...chunk_count-1 as files inside that folder.

You should also receive the total number of chunks through a header and after uploading compare how many chunks you have. When you have all the chunks just assemble them in the order of their chunk id. Care should be taken if you use the filesystem for this that all the files are actually fully written (typically if total size matches original size). A database makes this much simpler as you can insert a row in it when you have all the data.

A workaround for the filesystem way to make sure all your files are completely written is to write them in a different folder and move them to the destination folder upon completing the write.. both folders should be on the same filesystem so the move doesn't generate a copy + delete instead.

相关问答

我终于自己找到了原因: 检查呼叫的文件大小是以字符串形式返回的,但必须是数字 。 改变这一行 data.uploadedBytes = respData && respData.size;

至 data.uploadedBytes = respData && Number(respData.size);

解决了这个问题。 ======== 详细的解释 为什么它失败, data.uploadedBytes是String类型而不是Number: 在bluimp实现中的某个地方,下一个块的File-

...

我身边的一切都很好。 我的要求是正确的,但昨天谷歌服务似乎有问题(28.09.2014)。 现在一切都很好。 Everything was fine on my side. My request was correct, but there seemed to be a problem with googles services yesterday(28.09.2014). Everything works fine now.

事实证明@Brandan的博文实际上遗漏了一个重要指令: upload_state_store /tmp;

我补充说,现在一切都按预期工作。 It turns out that @Brandan's blog post actually leaves out one important directive: upload_state_store /tmp;

I added that and now everything works as expected.

在我看来,你需要与gui一起讨论javascript方面,或者至少从他那里获取完成的脚本并查看代码,很可能块号将在请求的标题之一中发送。 由于你将在不同的PHP脚本中接收块我建议你将它们存储在数据库或文件系统中,因为你需要添加块号,如果你真的想要去文件系统,那么文件系统会更难一些路径我建议你将它们存储在一个文件夹中,该文件夹的名称和文件名为0 ... chunk_count-1作为该文件夹中的文件。 您还应该通过标题收到块的总数,并在上传后比较您有多少块。 当你拥有所有块时,只需按照块ID的顺序组

...

从上面的代码看,您的上传路径似乎不正确: $upload_dir = "/public_html/site/$companyfolder/uploads";

应该是这样的: $upload_dir = "/home/youruser/public_html/site/{$companyfolder}/uploads";

目录需要是绝对路径或相对路径。 当它是相对的时,它需要相对于被调用的PHP所在的位置。 所以你可以把它用作./site/{$companyfolder}/uploads ,例如

...

一位朋友刚刚问我这个问题,我相信简短的答案是肯定的......有警告。 相关API由https://msdn.microsoft.com/en-us/library/system.net.http.httpcontentmultipartextensions(v=vs.118).aspx上定义的扩展方法提供。 我一直在寻找这些方法的同步版本,但无济于事。 显然, ReadAsMultipartAsync的返回值是Task ,您可以在其上调用Wait()来强制同步。 然后,您可以省略控制

...

您可以使用ASIHTTPRequest执行此操作,可在此处获取: http ://allseeing-i.com/ASIHTTPRequest/How-to-use 向下滚动到“直接从磁盘流式传输请求主体” You can do this using ASIHTTPRequest, available here: http://allseeing-i.com/ASIHTTPRequest/How-to-use Scroll way down to "Streaming request bodies

...

以下是我对上述问题的测试结果: 开发服务器不支持上传的分块传输编码。 正如Stuart所说,生产服务器确实支持它。 (唷) 我将报告任何依赖于指定上传大小限制,但我怀疑它是否重要。 不幸的是,我必须编写两个版本的代码,一个用于在开发服务器上进行测试,另一个用于在生产服务器上运行,但这绝对是一个可接受的方案。 Here are the result of my tests regarding the questions above: The development server does not s

...

试试这段代码: 创建.net应用程序(例如控制台应用程序) 安装Microsoft Team Foundation Server扩展客户端程序包 码: var u = new Uri("https://xxx.visualstudio.com");

VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "[PAT]"));

v

...

查看示例代码,似乎HTML文件需要从http://localhost:3000/uploads返回一些HTML。 问题是为什么/uploads端点没有返回任何东西,而是返回404响应? 答案就在于node.js应用程序中的主要可执行Javascript文件。 可能是一个名为server.js或index.js的文件。 下面是一个如何为您创建正确的node.js应用程序HTML文件的示例: server.js app.all('/uploads', function (req, res) {

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值