我正在尝试创建一个使用/上传图像文件的API
我已经像这样配置了我的应用:
ResourceConfig文件
@ApplicationPath("api")
public class appConfig extends ResourceConfig {
public appConfig() {
// Register resources and providers using package-scanning.
packages("src.main.java.org.vaad.vaadAPI");
register(MultiPartFeature.class);
register(LoggingFilter.class);
// temp disabled for testing
}
Run Code Online (Sandbox Code Playgroud)
资源文件:
@POST
@Path("/user/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
String SERVER_UPLOAD_LOCATION_FOLDER = "C://Upload_Files/";
String filePath = SERVER_UPLOAD_LOCATION_FOLDER + contentDispositionHeader.getFileName();
// save the file to the server
// saveFile(fileInputStream, filePath);
String output = "File saved to server location : " + filePath;
return Response.status(200).build();
}
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<dependency> …Run Code Online (Sandbox Code Playgroud)