使用JAVA中的jquery文件上传插件分块上传文件 [英] File upload in chunks using jquery file upload plugin in JAVA

查看:439
本文介绍了使用JAVA中的jquery文件上传插件分块上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用blueimp JQuery文件上传插件上传大文件(大于1 GB).使用maxChunkSize配置发现,可以从客户端分块上传文件.服务器,我们可以获取块大小& Content-Range&的文件名Content-Disposition标头.

Trying to use blueimp JQuery file upload plugin to upload large files( greater than 1 GB). Found using the maxChunkSize configuration allows to do the file upload in chunks from client side. Server we can get chunk size & file name using Content-Range & Content-Disposition headers.

我的服务器是Weblogic,并且在Servlet中编写服务器端代码.

My server is Weblogic and writing server side code in a Servlet.

这是我的问题:

  1. 服务器端:如何知道请求是否为最后一个块?
  2. 服务器端如何将接收到的所有块数据写入单个文件?
  3. 由于每个块都将作为单独的请求发送,因此我如何识别分块的请求与同一文件相关?

推荐答案

在github上查看插件的Wiki-其中包含有关分块文件上传的部分.

Check the wiki of the plugin on github - it has a section on chunked file uploads.

来自 Wiki :

示例 PHP上传处理程序支持分块上传 框.

The example PHP upload handler supports chunked uploads out of the box.

要支持分块上传,上传处理程序将使用 内容范围标头,由每个插件 块.

To support chunked uploads, the upload handler makes use of the Content-Range header, which is transmitted by the plugin for each chunk.

检查上面链接的示例PHP代码.

Check the example PHP code linked above.

服务器端:如何知道请求是否为最后一个块?

Server side: How to know that the request is last chunk or not ?

每个Content-Range请求标头将包含该请求中包含的文件字节范围以及文件的字节总数.因此,您可以对照字节总数检查范围的结束值,以确定请求是否包含最后一个块.

Each Content-Range request header will contain the range of bytes of the file contained in that request as well as the total number of bytes of the file. So, you can check the end value of the range against the total number of bytes to determine if the request contains the last chunk or not.

检查部分中给出的示例在W3C的网站上.

Check the example given in this section on W3C's website.

服务器端如何将接收到的所有块数据写入单个文件?

Server side How to write all the received chunks data into single file ?

您可以将内存中的所有块收集到一个数组中,然后一次将它们写入文件中-但这对于较大的文件可能效率不高. Java的IO API通过提供初始偏移量来提供写入文件部分的方法.检查问题.

You can collect all the chunks in memory in an array and then write them to a file in one-go - but this can be inefficient for larger files. Java's IO API provides methods to write to sections of files by providing an initial offset. Check this question.

由于每个块都将作为单独的请求发送,因此我如何识别分块的请求与同一文件相关?

How can I identify chunked requests are related to same file, since each chunk will send as a individual request ?

检查每个请求中的Content-Range标头-如果一个请求具有该标头,则它是许多块上载请求之一.使用标头的值,您可以找出该请求中包含文件的哪个部分/部分.

Check for the Content-Range header in each request - if a request has that header then it is one of the many chunk-upload requests. Using the value of the header, you can figure out which part/section of the file is contained in that request.

此外,请求中的Content-Disposition标头将包含文件名,您可以使用该文件名链接同一文件的各种请求.

Also, the Content-Disposition header in the request will contain the file name using which you can link various requests of the same file.

这篇关于使用JAVA中的jquery文件上传插件分块上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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