从公共汽车到请求柱的管道流
2022-09-04 02:36:40
我有我正在发布到一个快速端点,在下面形成标记:multipart/form-data
/data/upload
form(enctype="multipart/form-data", action="/data/upload", method="post")
input(type="file", name="data")
我正在使用读取文件流,这工作正常。从那里,我想使用npm模块再次将流发送到第二个Java后端。JS 客户机/Java 服务器代码如下:busboy
multipart/form-data
request
req.busboy.on('file', function (fieldName, fileStream, fileName, encoding, mimeType) {
var reqBody = {
url: server.baseURL + 'api/data',
headers: {
'Connection': 'keep-alive',
'Content-Type': 'multipart/form-data'
},
formData: {
file: fileStream
}
};
request.post(reqBody, function (err, r, body) {
// Do rendering stuff, handle callback
});
});
Java endpoint (api/data)
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void addData(FormDataMultiPart formDataMultiPart) {
// Handle multipart data here
}
我不认为我在这里正确发送文件...但是我很难弄清楚如何从客户端的临时文件直接管道传输流到而不读取/写入。有什么想法吗?multipart/form-data
busboy
request
Java 堆栈跟踪:
Apr 27, 2016 5:07:12 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 3 * Server has received a request on thread qtp1631904921-24
3 > POST http://localhost:8080/api/data
3 > Connection: keep-alive
3 > Content-Length: 199
3 > Content-Type: multipart/form-data; boundary=--------------------------331473417509479560313628
3 > Host: localhost:8080
Apr 27, 2016 5:07:12 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 3 * Server responded with a response on thread qtp1631904921-24
3 < 400
17:07:13.003 [qtp1631904921-24] WARN org.eclipse.jetty.http.HttpParser parseNext - bad HTTP parsed: 400 No URI for HttpChannelOverHttp@425137da{r=1,c=false,a=IDLE,uri=null}
拉哈特建议的更改:
31 var reqBody = {
32 url: server.baseURL + 'data',
33 headers: {
34 'Connection': 'keep-alive',
35 'Content-Type': 'multipart/form-data'
36 }
37 };
38
39 req.pipe(req.busboy.pipe(request.post(reqBody)));
抛出错误:
Error: Cannot pipe. Not readable.
at Busboy.Writable.pipe (_stream_writable.js:154:22)