使用"multipart/form-data"时出现严重错误.文件上传服务-Apache Jersey [英] Severe error for using "multipart/form-data" for a file upload service - Apache Jersey

查看:209
本文介绍了使用"multipart/form-data"时出现严重错误.文件上传服务-Apache Jersey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

SEVERE: Resource methods utilizing @FormParam and consuming "multipart/form-data" are no longer supported. See @FormDataParam

当对基于Apache Jersey的Rest Web服务的客户端Web访问完成时,我现在正在工作:

When a client web access is done for a Apache Jersey based Rest web service I am working right now:

@POST
@Path("upload")
@Consumes("multipart/form-data")
@Produces("text/plain")
public String uploadFile(@FormParam("file") File file, @FormParam("file") FormDataContentDisposition fileDetail) {
    String fileLocation = "/files/" + fileDetail.getFileName();
    System.out.println("File location: " + fileLocation);
    // Load image
    try {
        byte[] imageBytes = loadImage(fileLocation);
        MongoConnection conn = MongoUtil.getConnection();
        conn.connect("m1", "avatar"); 
        GridFS fs = new GridFS(conn.getDB());
        GridFSInputFile in = fs.createFile(imageBytes);
        in.save();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "1";
}

我尝试从@FormParam更改为@FormDataParam,但尚未解决.

I have tried changing from @FormParam to @FormDataParam but it's unresolved.

对此有什么解决办法?

推荐答案

您将必须下载并使用jersey-multipart.jar

You will have to download and use jersey-multipart.jar

这篇关于使用"multipart/form-data"时出现严重错误.文件上传服务-Apache Jersey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆