[英]Cannot upload a file with jersey
我沒有通過jersey上傳文件,但HTML和客戶端都會收到錯誤消息:
415-不支持的媒體類型
服務器說:
服務器拒絕此請求,因為請求實體的格式不受請求的方法所請求的資源支持。
@POST
@Path("file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public String uploadFile(
@FormDataParam("file") InputStream in,
@FormDataParam("file") FormDataContentDisposition fileDisposition){
String fullName = fileDisposition.getFileName();
try {
OutputStream os = new FileOutputStream(
new File("D://",fullName));
int index = 0;
byte[] buffer = new byte[256];
while( (index = in.read(buffer)) != -1){
os.write(buffer , 0 , index);
}
in.close();
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fullName;
}
那我該怎么辦?
真是笑話。
它需要一個名為mimepull.jar的jar,然后代碼運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.