建议放弃!!!
<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>