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

dubbox怎样上传文件?


建议放弃!!!


      

@cookier 我用的是rest-easy

接口:

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

        
        
            org.jboss.resteasy
            resteasy-multipart-provider
            3.0.16.Final
        
        
            org.jboss.resteasy
            resteasy-jaxrs
            3.0.16.Final
        
  

你可能感兴趣的:(Dubbo)