@ 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 ( ) && ! 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 ) ; }
Upload a new molgenis logo