src/main/java/org/opensrp/service/MultimediaService.java
/**
	 * Saves a multi-part file uploaded to the server
	 *
	 * @param multimediaDTO {@link MultimediaDTO} object populated with information about the file to be saved
	 * @param multimediaFile {@link MultipartFile} file to save to disk
	 *
	 * @return true if the file was saved else false
	 */
Saves a multi-part file uploaded to the server
@param multimediaDTO  MultimediaDTO object populated with information about the file to be saved
@param multimediaFile  MultipartFile file to save to disk

@return true if the file was saved else false
Saves a multi - part file uploaded to the server @param multimediaDTO MultimediaDTO object populated with information about the file to be saved @param multimediaFile MultipartFile file to save to disk @return true if the file was saved else false
public boolean uploadFile(MultimediaDTO multimediaDTO, MultipartFile multimediaFile) {
		if (!multimediaFile.isEmpty()) {
			try {
				multimediaDirPath = baseMultimediaDirPath + File.separator;
				String fileExt = ".jpg";
				switch (multimediaDTO.getContentType()) {
					case "application/octet-stream":
						multimediaDirPath += VIDEOS_DIR;
						fileExt = ".mp4";
						break;
					case "image/jpeg":
						multimediaDirPath += IMAGES_DIR;
						fileExt = ".jpg";
						break;
					case "image/gif":
						multimediaDirPath += IMAGES_DIR;
						fileExt = ".gif";
						break;
					case "image/png":
						multimediaDirPath += IMAGES_DIR;
						fileExt = ".png";
						break;
					default:
						throw new IllegalArgumentException("Unknown content type : " + multimediaDTO.getContentType());
				}
				String fileName;
				if (MULTI_VERSION.equals(multimediaDTO.getFileCategory())) {
					String dirPath = multimediaDirPath + File.separator + multimediaDTO.getCaseId();
					new File(dirPath).mkdirs();
					fileName = dirPath + File.separator + multimediaFile.getOriginalFilename();
				} else {
					new File(multimediaDirPath).mkdirs();
					fileName = multimediaDirPath + File.separator + multimediaDTO.getCaseId() + fileExt;
				}
				multimediaDTO.withFilePath(fileName);
				File multimediaFilePath = new File(fileName);
				multimediaFile.transferTo(multimediaFilePath);
				return true;
			}
			catch (Exception e) {
				logger.error("", e);
				return false;
			}
		} else {
			return false;
		}
	}
public boolean uploadFile ( MultimediaDTO multimediaDTO , MultipartFile multimediaFile ) { if ( ! multimediaFile . isEmpty ( ) ) { try { multimediaDirPath = baseMultimediaDirPath + File . separator ; String fileExt = ".jpg" ; switch ( multimediaDTO . getContentType ( ) ) { case "application/octet-stream" : multimediaDirPath += VIDEOS_DIR ; fileExt = ".mp4" ; break ; case "image/jpeg" : multimediaDirPath += IMAGES_DIR ; fileExt = ".jpg" ; break ; case "image/gif" : multimediaDirPath += IMAGES_DIR ; fileExt = ".gif" ; break ; case "image/png" : multimediaDirPath += IMAGES_DIR ; fileExt = ".png" ; break ; default : throw new IllegalArgumentException ( "Unknown content type : " + multimediaDTO . getContentType ( ) ) ; } String fileName ; if ( MULTI_VERSION . equals ( multimediaDTO . getFileCategory ( ) ) ) { String dirPath = multimediaDirPath + File . separator + multimediaDTO . getCaseId ( ) ; new File ( dirPath ) . mkdirs ( ) ; fileName = dirPath + File . separator + multimediaFile . getOriginalFilename ( ) ; } else { new File ( multimediaDirPath ) . mkdirs ( ) ; fileName = multimediaDirPath + File . separator + multimediaDTO . getCaseId ( ) + fileExt ; } multimediaDTO . withFilePath ( fileName ) ; File multimediaFilePath = new File ( fileName ) ; multimediaFile . transferTo ( multimediaFilePath ) ; return true ; } catch ( Exception e ) { logger . error ( "" , e ) ; return false ; } } else { return false ; } }
Saves a multi-part file uploaded to the server
 @param multimediaDTO {@link MultimediaDTO} object populated with information about the file to be saved
 @param multimediaFile {@link MultipartFile} file to save to disk
Saves a multi - part file uploaded to the server @param multimediaDTO { @link MultimediaDTO } object populated with information about the file to be saved @param multimediaFile { @link MultipartFile } file to save to disk
// String baseMultimediaDirPath = System.getProperty("user.home"); // allow saving multiple multimedia associated with one client // overwrite previously saved image