changed the way we get content-type during file upload.
authormh <mh>
Fri, 19 Oct 2001 14:05:18 +0000 (14:05 +0000)
committermh <mh>
Fri, 19 Oct 2001 14:05:18 +0000 (14:05 +0000)
we check oreilly method by default (c. type sent by browser) and only if it is
likely wrong to we go by .extension.

also added some media type entries

dbscripts/populate_mediatyp.sql
source/mir/misc/StringUtil.java
source/mircoders/producer/ProducerStartPage.java
source/mircoders/servlet/ServletModuleOpenIndy.java

index 74210e3..390953f 100755 (executable)
@@ -12,7 +12,7 @@
 -- Disable triggers
 UPDATE "pg_class" SET "reltriggers" = 0 WHERE "relname" = 'media_type';
 
-INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (2,'unknown','application/octet-stream','--','UploadedMedia',NULL);
+INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (2,'unknown','application/octet-stream','Generic','UploadedMedia',NULL);
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (3,'jpg','image/gif','ImagesGif','Images',NULL);
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (4,'mp3','audio/mp3','Audio','UploadedMedia',NULL);
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (5,'jpg','image/jpeg','ImagesJpeg','Images',NULL);
@@ -20,11 +20,10 @@ INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcnam
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (7,'mpg','video/mpeg','Video','UploadedMedia',NULL);
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (8,'mov','video/quicktime','Video','UploadedMedia',NULL);
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (9,'avi','video/x-msvideo','Video','UploadedMedia',NULL);
-
-
-
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (10,'ra','audio/vnd.rn-realaudio','RealAudio','UploadedMedia',NULL);
 INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (11,'rm','video/vnd.rn-realvideo','RealVideo','UploadedMedia',NULL);
+INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (12,'ra','audio/x-pn-realaudio','RealAudio','UploadedMedia',NULL);
+INSERT INTO "media_type" ("id","name","mime_type","classname","tablename","dcname") VALUES (13,'mp3','audio/x-mp3','Audio','UploadedMedia',NULL);
 
 
 -- Enable triggers
index 54d70c6..49004c1 100755 (executable)
@@ -256,6 +256,17 @@ public final class StringUtil {
   }
 
   /**
+   * Checks to see if the path is absolute by looking for a leading file
+   * separater
+   * @todo deal with windows drive letters.
+   * @param path
+   * @return
+   */
+  public static boolean isAbsolutePath (String path) {
+    return  path.startsWith(File.separator);
+  }
+
+  /**
    * Löscht Slash am Anfang des Strings
    * @param path
    * @return
index 133b698..af3f9b5 100755 (executable)
@@ -130,7 +130,7 @@ public class ProducerStartPage extends Producer {
                 theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName);
               }
 
-              //the best media type
+              //the "best" media type to show
               if (mediaHandler.isVideo()) {
                 tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo");
                 iconAlt = "Video";
index ad77a2e..8efa6d1 100755 (executable)
@@ -246,22 +246,41 @@ public class ServletModuleOpenIndy extends ServletModule
         MpRequest mpReq = (MpRequest)it.next();
         String fileName = mpReq.getFilename();
 
-        //This is just a temporary way to get the content-type via
-        //the .extension , we need to use a magic method, by looking
-        //at the header (first few bytes) of the file.
-        //the Oreilly method sucks cause it relies on the
-        //content-type the client browser sends and that's
-        //too often application-octet stream. -mh
-        String contentType = FileUtil.guessContentTypeFromName(fileName);
+        //get the content-type from what the client browser
+        //sends us. (the "Oreilly method")
+        String contentType = mpReq.getContentType();
+
+        theLog.printError("FROM BROWSER: "+contentType);
+
+        //if the client browser sent us unknown (text/plain is default)
+        //or if we got application/octet-stream, it's possible that
+        //the browser is in error, better check against the file extension
+        if (contentType.equals("text/plain") || 
+            contentType.equals("application/octet-stream")) {
+            /** 
+             * This is just a temporary way to get the content-type via
+             * the .extension , we could maybe use a magic method, by looking
+             * at the header (first few bytes) of the file. (like the file(1)
+             * command).
+             * The Oreilly method  relies on the content-type that the client 
+             * browser sends and that sometimes is application-octet stream with
+             * broken/mis-configured browsers.
+             * 
+             * The map file should be Mir/content-types.properties, it's the 
+             * default Sun Java file with some additional entries that it did 
+             * not have. So if you support a new media type you have to make 
+             * sure that it is in this file -mh
+             */
+            contentType = FileUtil.guessContentTypeFromName(fileName);
+            if (contentType==null)
+                contentType = "text/plain"; // rfc1867 says this is the default
+        }
         HashMap mediaValues = new HashMap();
 
         theLog.printError("CONTENT TYPE IS: "+contentType);
         
-        //The map file should be Mir/content-types.properties, it's the 
-        //default Sun Java file+ some entries that it did not have.
-        //so if you support a new media type you have to make sure that
-        //it is in this file -mh
-        if ((contentType==null) || (contentType=="application/octet-stream")) {
+        if (contentType.equals("text/plain") || 
+            contentType.equals("application/octet-stream")) {
           throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
         }