2014-08-30 94 views
0

我做球衣文件上传,但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; 
} 

那么,我该怎么办?

回答

0

真是个笑话。

它需要一个名为mimepull.jar的jar,然后代码运行良好。