URL:http:// localhost:8080/RESTfulExample/rest/file/upload 方法:POST
回应:
相同的代码正在使用html表单,但在postman中它投掷了400个BAD REQUEST,我在google上查找解决方案并发现边界丢失,如何解决?因为我必须通过Jquery和rest客户端从移动应用程序和Web客户端等多个客户端接收文件.
@Path("/file")
public class UploadFileService {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
try {
String uploadedFileLocation = "/home/nash/" + fileDetail.getFileName();
// save it
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded to : " + uploadedFileLocation;
System.out.println("File uploaded..........");
return Response.status(200).entity(output).build();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception " + e);
return null;
}
}
// save uploaded file to new location
private void writeToFile(InputStream …Run Code Online (Sandbox Code Playgroud)