Dubbo 接收用户上传文件的方法(resteasy)

dubbox怎样上传文件?


建议放弃!!!


      <p><a class="user-mention" data-hovercard-user-id="5186526" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/cookier" aria-describedby="hovercard-aria-description">@cookier</a>  我用的是rest-easy<br>

接口:

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.bean.DiskFile;

@Path("upload")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
@Produces({ ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8 })
public interface Upload{

    @Path("/file")
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA) 
    public String uploadFile(@MultipartForm DiskFile file);

}

实现类:

public class UploadImpl implements Upload{

    public String uploadFile(DiskFile file) {
        String fileName = file.getFileName() ;
        InputStream in = new ByteArrayInputStream(diskFile.getFileData());  
    }

}

DiskFile类:

import javax.ws.rs.FormParam;
import org.jboss.resteasy.annotations.providers.multipart.PartType;

public class DiskFile {

    private byte[] fileData;
    @FormParam("fileName")
    private String fileName; // 文档名称

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public byte[] getFileData() {
        return fileData;
    }

    @FormParam("file")
    @PartType("application/octet-stream")
    public void setFileData(byte[] fileData) {
        this.fileData = fileData;
    }

}

rest-easy相关的pom

        <!-- jax-rs上传文件 -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>3.0.16.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.16.Final</version>
        </dependency>
  </td>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值