我们的Web服务器(配置为ssl - > apache - > jetty)随机拒绝带有400 Bad Request错误代码的多部分上传POST请求.apache错误日志(在信息级别)显示以下两个错误:
[info] [client x1.y1.z1.w1] (70007)The timeout specified has expired: SSL input filter read failed.
[error] proxy: pass request body failed to x.y.z.w:8087 from x1.y1.z1.w1
[info] [client x1.y1.z1.w1] Connection closed to child 74 with standard shutdown
Run Code Online (Sandbox Code Playgroud)
要么
[info] [client x2.y2.z2.w2] (70014)End of file found: SSL input filter read failed.
[error] proxy: pass request body failed to x.y.z.w:8087 from x2.y2.z2.w2
[info] [client x2.y2.z2.w2] Connection closed to child 209 with standard shutdown
Run Code Online (Sandbox Code Playgroud)
这两种情况都是客户端在400 Bad Request中产生的.有时我们的jetty服务器甚至没有看到请求意味着它在apaches端被拒绝,有时它开始处理它只是被拒绝(这在我们的UploadFilter中表现为MultipartException) …
我们有一个REST服务,它接受包含该hold 的MultiPart
POST请求.在REST服务内部,可以根据提供的数据创建文件.BodyParts
InputStream
我们希望根据其MultiPart
输入对执行文件操作的类进行单元测试.注意:Wo不想使用Jersey-Test!Grizzly没有加载我们需要将DAO和fileHandler服务注入REST服务类的spring应用程序上下文.我们明确要测试我们的fileHandler服务如何处理multiPart数据.
然而问题是,MultiPart
从REST客户端发出的内容与REST服务器收到的内容不同,因为泽西可能会对数据进行流式传输或其他任何操作.尝试测试(见下文)以下设置将导致
IllegalArgumentException [B cannot be cast to com.sun.jersey.multipart.BodyPartEntity
Run Code Online (Sandbox Code Playgroud)
(只是片段,我省略了明显的东西):
byte[] bytes = FileManager.readImageFileToArray(completePath, fileType);
MultiPart multiPart = new MultiPart().
bodyPart(new BodyPart(bytes, MediaType.APPLICATION_OCTET_STREAM_TYPE)).
bodyPart(new BodyPart(fileName, MediaType.APPLICATION_XML_TYPE)).
bodyPart(new BodyPart(senderId, MediaType.APPLICATION_XML_TYPE));
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
WebResource webResource = client.resource(requestUrl);
Builder builder = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE);
builder = addHeaderParams(builder, headerParams);
ClientResponse response = builder.post(ClientResponse.class, …
Run Code Online (Sandbox Code Playgroud) 我需要压缩zip(tar,gz,7z等)文件中的目录.没关系,但我需要创建彼此连接的多部分zip文件(如file1.part1.zip,file1.part2.zip)
如何在java中创建multipart zip文件?每个部件必须具有最大尺寸限制.
我试图弄清楚如何在Go中接受/接收HTTP Post.我只是希望能够接收文件,获取其mime类型并在本地保存文件.
我一整天都在搜索,但我能找到的是如何将文件发送到某个远程位置,但我发现的任何一个例子都没有收到它.
任何帮助,将不胜感激.
使用Justinas的例子,并与我现有的实验混合,我已经得到了这么多,但m.Post似乎永远不会被称为.
package main
import (
"fmt"
"io"
"net/http"
"os"
"github.com/codegangsta/martini"
"github.com/codegangsta/martini-contrib/render"
)
func main() {
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Directory: "templates", // Specify what path to load the templates from.
Layout: "layout", // Specify a layout template. Layouts can call {{ yield }} to render the current template.
Charset: "UTF-8", // Sets encoding for json and html content-types.
}))
m.Get("/", func(r render.Render) {
fmt.Printf("%v\n", "g./")
r.HTML(200, "hello", "world")
})
m.Get("/:who", func(args martini.Params, r render.Render) {
fmt.Printf("%v\n", …
Run Code Online (Sandbox Code Playgroud) 我已将最大文件大小设置为
multipart.maxFileSize: 1mb
multipart.maxRequestSize: 1mb
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@RequestMapping(method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@Secured(Privileges.CAN_USER_READ)
public void create(@RequestParam("file")final MultipartFile file,Principal principal) throws IllegalStateException, IOException,MultipartException{
medicalHistoryService.create(new MedicalHistory(file));
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息
2016-03-03 13:48:24.560 WARN 4992 --- [nio-8080-exec-1] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9288401) exceeds the configured maximum (1048576)
2016-03-03 13:48:25.545 WARN 4992 --- [nio-8080-exec-2] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the …
Run Code Online (Sandbox Code Playgroud) spring multipartform-data multipart spring-boot embedded-tomcat-8
目标是让Node.js / hapi API服务器通过两件事来响应浏览器的AJAX请求:
这是两个单独的项目,只是因为二进制数据无法轻松存储在JSON中。否则,这将是单个资源。但是,最好在单个响应中发送它们。
我们通过将它们上传到单个请求中multipart/form-data
。在这种情况下,浏览器提供了一种内置的机制来序列化主体,并且大多数服务器端框架都知道如何解析主体。但是,如何在相反的方向做出相同的反应呢?即,服务器应如何序列化主体以将其传输给客户端?
据我所知,这multipart/mixed
可能是一种有用的内容类型。但是对此几乎没有任何谈论。大多数人似乎诉诸于提供两条单独的GET
路线,每条路线一条。我之所以不喜欢它,是因为它使您更容易进入比赛条件。我想念什么?
另请参阅hapijs / discuss#563中的我的问题。
我想使用apachebench(ab)来测试文件上传性能.我已阅读手册,无法找到实现目标的方法.
我的目标是尝试使用POST方法和multipart/form-data格式通过HTTP请求上传文件.
ab支持"-p POST-FILE",但我只能找到格式key = value&key2 = value2
我要发送的帖子数据是什么
内容类型:multipart/form-data; 边界= ---- WebKitFormBoundaryuUlX4554LPBjInc5
------ WebKitFormBoundaryuUlX4554LPBjInc5 Content-Disposition:form-data; NAME = "文件"; filename ="411c40d9.jpg"内容类型:image/jpeg
XXXXXXXXXXXXXXX(图像数据)YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
我google了一段时间,找不到任何相关的文章或方法来实现这一点.我使用cURL,它工作正常,但我想做压力测试.所以我需要用ab来实现这个目标.
有什么建议?
我想检查上传文件的进度HttpUrlConnection
.我怎么能这样做?我曾尝试在写入数据时计算字节数,OutputStream
但这是错误的,因为只有在我调用时才会发生真正的上传conn.getInputStream()
,因此我需要以某种方式检查inputStream.这是我的代码:
public static void uploadMovie(final HashMap<String, String> dataSource, final OnLoadFinishedListener finishedListener, final ProgressListener progressListener) {
if (finishedListener != null) {
new Thread(new Runnable() {
public void run() {
try {
String boundary = getMD5(dataSource.size()+String.valueOf(System.currentTimeMillis()));
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.setCharset(Charset.forName("UTF-8"));
for (String key : dataSource.keySet()) {
if (key.equals(MoviesFragmentAdd.USERFILE)) {
FileBody userFile = new FileBody(new File(dataSource.get(key)));
multipartEntity.addPart(key, userFile);
continue;
}
multipartEntity.addPart(key, new StringBody(dataSource.get(key),ContentType.APPLICATION_JSON));
}
HttpEntity entity = multipartEntity.build();
HttpURLConnection conn = (HttpsURLConnection) new URL(URL_API + …
Run Code Online (Sandbox Code Playgroud) upload android multipart httpurlconnection android-progressbar
spring boot 应用程序中的多部分文件上传不适用于 tomcat 版本 9.0.31。但是这个功能在旧版本 9.0.30 上工作正常。但是这个版本有一个漏洞,被迫升级版本。请参阅下面给出的错误
"timestamp": "2020-03-09T08:01:56.169+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.impl.IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly",
Run Code Online (Sandbox Code Playgroud)
错误日志如下
nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.impl.IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly] with root causeorg.apache.tomcat.util.http.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
Run Code Online (Sandbox Code Playgroud)
请帮助解决这个问题。
旧系统会向我发送以下内容:
POST /xml HTTP/1.1
Host: localhost:9000
User-Agent: curl/7.64.1
Accept: */*
Content-Length: 321
Content-Type: multipart/mixed; boundary=------------------------a9dd0ab37a224967
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part1"
Content-Type: text/xml
<foo>bar</foo>
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part2"
Content-Type: application/json
{'foo': 'bar'}
--------------------------a9dd0ab37a224967--
Run Code Online (Sandbox Code Playgroud)
我需要将第一部分解释为原始XElement
;对于第二部分,我想要通常的模型绑定。
我试试这个:
POST /xml HTTP/1.1
Host: localhost:9000
User-Agent: curl/7.64.1
Accept: */*
Content-Length: 321
Content-Type: multipart/mixed; boundary=------------------------a9dd0ab37a224967
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part1"
Content-Type: text/xml
<foo>bar</foo>
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part2"
Content-Type: application/json
{'foo': 'bar'}
--------------------------a9dd0ab37a224967--
Run Code Online (Sandbox Code Playgroud)
但 ASP.NET 不允许使用[FromBody]
.
如何让我的 ASP.NET Core 服务接收带有 content-type 的 http 请求multipart/mixed
?
multipart ×10
java ×3
http ×2
spring-boot ×2
android ×1
apache ×1
apachebench ×1
asp.net-core ×1
compression ×1
go ×1
hapijs ×1
https ×1
javascript ×1
jersey ×1
jetty ×1
mod-proxy ×1
node.js ×1
performance ×1
post ×1
rest ×1
server ×1
spring ×1
testing ×1
tomcat ×1
upload ×1
zip ×1