0
我面臨的問題是,在服務器上傳zip文件後,無法解壓。 我已經基於與下一個端點例如Dropwizard框架REST API:通過Dropwizard框架上傳後,Zip文件無法解壓縮
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/zip")
public class ImportResource {
@POST
public Response fileService(@FormDataParam("fileData") InputStream fileDataInputStream,
@FormDataParam("fileData") FormDataContentDisposition fileDataDetail) {
File newFile = new File("/Users/alexx/Documents/"+ fileDataDetail.getFileName());
try {
final OutputStream out = new FileOutputStream(newFile);
ByteStreams.copy(fileDataInputStream, out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Response.ok().build();
}
// save uploaded file to new location
private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) throws IOException {
int read;
final int BUFFER_LENGTH = 1024;
final byte[] buffer = new byte[BUFFER_LENGTH];
OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
while ((read = uploadedInputStream.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
out.flush();
out.close();
}
此外,在應用類我提供適當的類:
....
bootstrap.addBundle(new MultiPartBundle());
....
environment.jersey().register(MultiPartFeature.class);
上傳zip文件,它看起來像它上傳後,但它不能解壓縮,收到下一條消息:
(錯誤1 - 操作不允許)。
文本和圖像文件上傳並正確打開。
我跳過了什麼嗎?我應該添加額外的參數還是設置在某個地方? 謝謝你的答案!