serverWork.setOrientationLevel(UploadConstants.SERVER_ORIENTATION_VALUE);
}
public void createThumbnail(FileConversionContext conversionContext) throws Exception {
// Get file
AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
String mimeType = attDescription.getContentType();
File inFile = File.createTempFile("original_", attDescription.getMediaFileName());
conversionContext.downloadFile(inFile);
File outFile = File.createTempFile("thumb_", attDescription.getMediaFileName());
// Perform thumbnail
MultimediaConversionRequest request = new MultimediaConversionRequest();
request.setInFile( inFile );
request.setThumbnailFile(outFile);
request.setThumbnailRequested(true);
MultimediaClass mmClass = MimeUtils.getMultimediaClassFromMimeType(mimeType);
if( MultimediaClass.IMAGE == mmClass ) {
// For image file, convert to appropriate file type
mmConverter.createImageThumbnail(request);
} else {
throw new Exception("Unknown multimedia class: "+mmClass);
}
// Compute attachment name
SystemFile thumbSf = SystemFile.getSystemFile(outFile);
String thumbnailAttachmentName = computeThumbnailName(attDescription.getAttachmentName(),"jpeg");
// Upload thumbnail
String thumbMimeType = thumbSf.getMimeType();
conversionContext.uploadFile(thumbnailAttachmentName, outFile, thumbMimeType);
// Report thumbnail object
if( request.isThumbnailCreated() ) {
AttachmentDescriptor thumbnailObj = conversionContext.getAttachmentDescription(thumbnailAttachmentName);
thumbnailObj.setStatus(UploadConstants.UPLOAD_STATUS_ATTACHED);
thumbnailObj.setFileClass("image");
thumbnailObj.setOriginalName(attDescription.getOriginalName());
thumbnailObj.setSource(attDescription.getAttachmentName());
thumbnailObj.setSize(outFile.length());
thumbnailObj.setContentType(thumbSf.getMimeType());
thumbnailObj.setEncodingType(thumbSf.getMimeEncoding());
if( request.getThumbnailHeight() != 0
&& request.getThumbnailWidth() != 0
) {
thumbnailObj.setHeight(request.getThumbnailHeight());
thumbnailObj.setWidth(request.getThumbnailWidth());
}
attDescription.setThumbnailReference(thumbnailAttachmentName);
}