I am making a Spring Boot Application to serve images. My createFile
method tries to get URI from the POST request but it is unable to resolve the files' name.
Down below I am trying to make a POST request for serving images. I have the the error on resolve
method under URI. I tried 3 imports as stated below:
//1
import java.net.URI;
//2
import com.sun.org.apache.xml.internal.utils.URI;
//3
import com.sun.org.apache.xerces.internal.util.URI;
None of these seems to work.
Below is the POST request I am trying to make to serve images.
private static final String BASE_PATH = "/images";
//for Curl. Development and testing
@RequestMapping(method = RequestMethod.POST,value = BASE_PATH )
@ResponseBody
public ResponseEntity<?> createFile(@RequestParam("file") MultipartFile file, HttpServletRequest servletRequest) {
try {
imageService.createImage(file);
final URI locationUri = new Uri(servletRequest.getRequestURL().toString() + "/")
.resolve(file.getOriginalFilename() + "/raw");//error here on resolve
return ResponseEntity.created(locationUri)
.body("Succesfull" + file.getOriginalFilename());
} catch (IOException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Could not find " + file.getOriginalFilename() + "=>" + e.getMessage());
}
}