@Override public File downloadFile(String url, String folderName, String fileName) { try { File folder = new File(fileStore.getStorageDir(), folderName); folder.mkdir(); try (InputStream in = new URL(url).openStream()) { String filename = folderName + '/' + fileName; return fileStore.store(in, filename); } } catch (IOException e) { throw new UncheckedIOException(e); } } }
private File storeFile( FileStore fileStore, String key, String extension, String targetEntityName, String jobIdentifier, InputStream in) throws IOException { // no extension given, default is excel if (!StringUtils.isNotEmpty(extension)) { extension = "xlsx"; } String relativePath = "bucket_" + jobIdentifier; File folder = new File(fileStore.getStorageDir(), relativePath); folder.mkdir(); String filename; if (StringUtils.isNotEmpty(targetEntityName) && !ExcelFileExtensions.getExcel().contains(extension)) { filename = String.format("%s%s%s.%s", relativePath, File.separatorChar, targetEntityName, extension); } else { String fileRoot = key.replaceAll("[\\/:*?\"<>|]", "_"); filename = String.format("%s%s%s.%s", relativePath, File.separatorChar, fileRoot, extension); } return fileStore.store(in, filename); }
/** Upload a new molgenis logo */ @PreAuthorize("hasAnyRole('ROLE_SU')") @PostMapping("/upload-logo") public String uploadLogo(@RequestParam("logo") Part part, Model model) throws IOException { String contentType = part.getContentType(); if ((contentType == null) || !contentType.startsWith("image")) { model.addAttribute("errorMessage", ERRORMESSAGE_LOGO); } else { // Create the logo subdir in the filestore if it doesn't exist File logoDir = new File(fileStore.getStorageDir() + "/logo"); if (!logoDir.exists()) { if (!logoDir.mkdir()) { throw new IOException("Unable to create directory [" + logoDir.getAbsolutePath() + "]"); } } // Store the logo in the logo dir of the filestore String file = "/logo/" + FileUploadUtils.getOriginalFileName(part); try (InputStream inputStream = part.getInputStream()) { fileStore.store(inputStream, file); } // Set logo appSettings.setLogoNavBarHref(file); } return init(model); } }
fileStore.getStorageDir() + separatorChar + FILE_STORE_PLUGIN_APPS_PATH + separatorChar + app.getId() + separatorChar);
.addResourceHandler("/" + PATH_SEGMENT_APPS + "/**") .addResourceLocations( "file:///" + fileStore.getStorageDir() + '/' + FILE_STORE_PLUGIN_APPS_PATH + '/'); registry .addResourceHandler("/webjars/**")