/** * Reads content from the body of a request and writes it to a file in the given directory. * * If the file already exists, the directory content will be deleted recursively * before creating the new file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param request The request. * * @return The file object representing the newly written file. * * @throws IOException Any I/O errors that occur. * * @deprecated use {@link #handleBinUpload(String, File, boolean, Request)}. */ public static File handleBinUpload(String fileName, File directory, Request request) throws IOException { return handleBinUpload(fileName, directory, true, request); }
/** * Reads content from the body of a request and writes it to a file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param deleteDirectoryContent Delete directory content if the file already exists. * @param request The request. * @return The file object representing the newly written file. * @throws IOException Any I/O errors that occur. * <p>TODO: move this to IOUtils. */ public static org.geoserver.platform.resource.Resource handleBinUpload( String fileName, org.geoserver.platform.resource.Resource directory, boolean deleteDirectoryContent, HttpServletRequest request) throws IOException { return handleBinUpload(fileName, directory, deleteDirectoryContent, request, null); }
/** * This function gets the stream of the request to copy it into a file. * @deprecated use {@link #handleBinUpload(String, File, Request)}. */ public static File handleBinUpload(String datasetName, String extension, Request request) throws IOException, ConfigurationException { final File dir = GeoserverDataDirectory.findCreateConfigDir("data"); return handleBinUpload( datasetName + "." + extension, dir, request ); }
/** * Verifies mime type * * @param directory * @param filename * @param request * @return */ private Resource fileUpload(Resource directory, String filename, HttpServletRequest request) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info( "PUT file: mimetype=" + request.getContentType() + ", path=" + directory.path()); } try { return RESTUtils.handleBinUpload(filename, directory, false, request); } catch (IOException problem) { throw new RestException( problem.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, problem); } }
/** * Verifies mime type and use {@link RESTUtils} * * @param directory * @param filename * @param request * @return */ protected Resource fileUpload(Resource directory, String filename, HttpServletRequest request) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info( "PUT file: mimetype=" + request.getContentType() + ", path=" + directory.path()); } try { return RESTUtils.handleBinUpload(filename, directory, false, request); } catch (IOException problem) { throw new RestException( problem.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, problem); } } // @Override
private File doFileUpload() { try { getResponse().setStatus(Status.SUCCESS_ACCEPTED); File directory = catalog.getResourceLoader().findOrCreateDirectory(getDirectoryPath(getRequest())); if (LOGGER.isLoggable(Level.INFO)) { MediaType mediaType = getRequest().getEntity().getMediaType(); LOGGER.info("PUT file: mimetype=" + mediaType + ", path=" + directory.getAbsolutePath()); } return RESTUtils.handleBinUpload(getAttribute("template") + "." + MEDIATYPE_FTL_EXTENSION, directory, false, getRequest()); } catch (IOException e) { throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e); } }
String method = (String) getRequest().getResourceRef().getLastSegment(); if (method != null && method.toLowerCase().startsWith("file.")) { uploadedFile = RESTUtils.handleBinUpload(store + "." + format, directory, getRequest());
RESTUtils.handleBinUpload( filename, directory, cleanPreviousContents, request, workspace); } else if (method == UploadMethod.url) {