2014-08-30 56 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,然後代碼運行良好。