Multipart File Upload on Google Appengine using jersey-1.7(使用 jersey-1.7 在 Google Appengine 上上传多部分文件)
问题描述
我用 Jersey 在 Google Appengine 上编写了一个应用程序来处理简单的文件上传.这在球衣 1.2 上运行良好.在更高版本(当前 1.7)中,引入了 @FormDataParam 来处理多部分/表单输入.我正在使用 jersey-multipart 和 mimepull 依赖项.似乎新的做法是在 appengine 中创建我们都知道是非法的临时文件...
I wrote an application on Google Appengine with Jersey to handle simple file uploading. This works fine when it was on jersey 1.2. In the later versions (current 1.7) @FormDataParam is introduced to handle multipart/form inputs. I am using jersey-multipart and the mimepull dependency. It seems that the new way of doing it is creating temporary files in appengine which we all know is illegal...
由于 Jersey 现在应该与 AppEngine 兼容,我是否在这里遗漏了什么或做错了什么?
Am I missing something or doing something wrong here since Jersey is now supposedly compatible with AppEngine?
@POST
@Path("upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(@FormDataParam("file") InputStream in) { .... }
上述异常调用时会失败...
The above will fail when called with these exceptions...
/upload
java.lang.SecurityException: Unable to create temporary file
at java.io.File.checkAndCreate(File.java:1778)
at java.io.File.createTempFile(File.java:1870)
at java.io.File.createTempFile(File.java:1907)
at org.jvnet.mimepull.MemoryData.createNext(MemoryData.java:87)
at org.jvnet.mimepull.Chunk.createNext(Chunk.java:59)
at org.jvnet.mimepull.DataHead.addBody(DataHead.java:82)
at org.jvnet.mimepull.MIMEPart.addBody(MIMEPart.java:192)
at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:235)
at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:176)
at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:101)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readMultiPart(MultiPartReaderClientSide.java:177)
at com.sun.jersey.multipart.impl.MultiPartReaderServerSide.readMultiPart(MultiPartReaderServerSide.java:80)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:139)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:77)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:538)
有人知道吗?有没有办法在防止 mimepull 创建临时文件的同时做事?
Anyone have a clue? Is there a way to do thing while preventing mimepull from creating the temporary file?
推荐答案
对于超出其默认大小的文件,multipart
将创建一个临时文件.为了避免这种情况——在 gae 上创建文件是不可能的——你可以在项目的资源文件夹中创建一个 jersey-multipart-config.properties
文件并将这一行添加到其中:
For files beyond its default size, multipart
will create a temporary file. To avoid this — creating a file is impossible on gae — you can create a jersey-multipart-config.properties
file in the project's resources folder and add this line to it:
bufferThreshold = -1
那么,代码就是你给的那个:
Then, the code is the one you gave:
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response post(@FormDataParam("file") InputStream stream, @FormDataParam("file") FormDataContentDisposition disposition) throws IOException {
post(file, disposition.getFileName());
return Response.ok().build();
}
这篇关于使用 jersey-1.7 在 Google Appengine 上上传多部分文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 jersey-1.7 在 Google Appengine 上上传多部分文件
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01