我需要使用Jersey的多个文件上传帮助.我使用以下代码使用Jersey上传单个文件.
package my.first.rest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
@Path("uploadfile")
public class Upload {
String location;
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String uploadfile(@FormDataParam("file") InputStream is, @FormDataParam("file") FormDataContentDisposition filedetail){
saveToDisk(is,filedetail);
return "File Uploaded Succesfully_"+location;
}
private void saveToDisk(InputStream is1,
FormDataContentDisposition filedetail) {
// TODO Auto-generated method stub
location = "E://upload/"+filedetail.getFileName();
try{
OutputStream out = new FileOutputStream(new File(location));
int read = 0;
byte[] bytes = …Run Code Online (Sandbox Code Playgroud)