我看过前 8kb 和我上传的文件内容是一致的,但是后面所有信息丢失,代码如下:
@
Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println(req.getContentLength());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(req.getContentLength());
IOUtils.copy(req.getInputStream(), byteArrayOutputStream);
byte[] bytes = byteArrayOutputStream.toByteArray();
Path path = Paths.get(rootPath + "/" + new PathGenerator(bytes).getPath());
storage.put(byteArrayOutputStream.toByteArray(), path);
}
private static void copy(InputStream in, OutputStream op, int length) throws IOException {
byte[] bytes = new byte[length];
while (in.available() > 0) {
int readLength = in.read(bytes);
op.write(bytes, 0, readLength);
}
}