roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r961558 - /roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
Date Thu, 08 Jul 2010 02:21:27 GMT
Author: snoopdave
Date: Thu Jul  8 02:21:27 2010
New Revision: 961558

URL: http://svn.apache.org/viewvc?rev=961558&view=rev
Log:
Fix for ROL-1871: Media File upload did not recognize PDF, saved it as "octet stream"

I was not able to duplicate this on my machine (Mac) and I suspect it happens only on Windows,
but sometimes when you upload a Media File, Struts cannot guess the content-type correctly
and defaults to an 'octet stream' type. This commit adds logic to double-check and whenever
an 'octet-stream' type file is uploaded, Roller will now attempt to use the file's extension
to guess a more accurate content-type.

https://issues.apache.org/jira/browse/ROL-1871

Modified:
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java?rev=961558&r1=961557&r2=961558&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
(original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
Thu Jul  8 02:21:27 2010
@@ -28,7 +28,6 @@ import org.apache.commons.lang.StringUti
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.FileIOException;
 import org.apache.roller.weblogger.business.MediaFileManager;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
@@ -36,6 +35,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.MediaFileDirectory;
 import org.apache.roller.weblogger.util.RollerMessages;
 import org.apache.roller.weblogger.util.RollerMessages.RollerMessage;
+import org.apache.roller.weblogger.util.Utilities;
 import org.apache.struts2.interceptor.validation.SkipValidation;
 
 
@@ -158,7 +158,22 @@ public class MediaFileAdd extends MediaF
                         mediaFile.setLength(     this.uploadedFiles[i].length());
                         mediaFile.setInputStream(new FileInputStream(this.uploadedFiles[i]));
                         mediaFile.setContentType(this.uploadedFilesContentType[i]);
-                        
+
+                        // insome cases Struts2 is not able to guess the content
+                        // type correctly and assigns the default, which is
+                        // octet-stream. So in cases where we see octet-stream
+                        // we double check and see if we can guess the content
+                        // type via the Java MIME type facilities.
+                        mediaFile.setContentType(this.uploadedFilesContentType[i]);
+                        if (mediaFile.getContentType() == null
+                                || mediaFile.getContentType().endsWith("/octet-stream"))
{
+                            
+                            String ctype = Utilities.getContentTypeFromFileName(mediaFile.getName());
+                            if (null != ctype) {
+                                mediaFile.setContentType(ctype);
+                            }
+                        }
+
                         manager.createMediaFile(getActionWeblog(), mediaFile, errors);
                         WebloggerFactory.getWeblogger().flush();
 



Mime
View raw message