/** * Retrieves a previously uploaded file from upl path * @param fileData File data * @param create Create path * @return Uploaded file path */ public String getFullPath(FileData fileData, boolean create) { // Variable definition String relativePath = fileData.getRelativePath(); Long size = fileData.getFileSize(); // Calculate max elements per folder if (relativePath == null && create) { relativePath = "tmp" + (size % maxFilesPerFolder); } else if (relativePath == null) { relativePath = ""; } // Calculate upload path String absolutePath = StringUtil.getAbsolutePath(fileData.getBasePath() + relativePath + AweConstants.FILE_SEPARATOR, applicationBasePath); // Generate folder (if not null) if (create) { fileData.setRelativePath(relativePath); new File(absolutePath).mkdirs(); } return absolutePath; }
fileData = new FileData(file.getName(), file.length(), "application/octet-stream"); fileData.setBasePath(file.getParent()); fileData.setFileName(downloadAnnotation.name());
/** * Transform fileData into a string * @param fileData File Data * @return Stringified filedata * @throws com.almis.awe.exception.AWException */ public String fileDataToString(FileData fileData) throws AWException { try { return EncodeUtil.encodeSymmetric(CompressionUtil.compress(StringUtil.compressJson(objectMapper.writeValueAsString(fileData)))); } catch (IOException exc) { throw new AWException(getLocale("ERROR_TITLE_READING_PARAMETERS"), getLocale("ERROR_TITLE_READING_PARAMETER", fileData.getFileName()), exc); } }