/** * Handles an upload using the EXTERNAL method. * * @param request * @throws IOException */ public static File handleEXTERNALUpload(Request request) throws IOException { //get the URL for this file to upload final InputStream inStream=request.getEntity().getStream(); final String stringURL=IOUtils.getStringFromStream(inStream); final URL fileURL=new URL(stringURL); final File inputFile= IOUtils.URLToFile(fileURL); if(inputFile!=null && inputFile.exists() && inputFile.canRead()) { return inputFile; } return null; }
/** * Handles an upload using the EXTERNAL method. * * @param request * @throws IOException */ public static org.geoserver.platform.resource.Resource handleEXTERNALUpload( HttpServletRequest request) throws IOException { // get the URL for this file to upload final String stringURL; File inputFile; try (InputStream inStream = request.getInputStream()) { stringURL = IOUtils.getStringFromStream(inStream); inputFile = new File(stringURL); if (!inputFile.exists()) { URL fileURL = new URL(stringURL); inputFile = IOUtils.URLToFile(fileURL); } } if (inputFile == null || !inputFile.exists()) { throw new RestException( "Failed to locate the input file " + stringURL, HttpStatus.BAD_REQUEST); } else if (!inputFile.canRead()) { throw new RestException( "Input file is not readable, check filesystem permissions: " + stringURL, HttpStatus.BAD_REQUEST); } return Files.asResource(inputFile); }
final File inputFile= IOUtils.URLToFile(fileURL); if(inputFile!=null && inputFile.exists() && inputFile.canRead()) { IOUtils.copyFile(inputFile, newFile);