From bc5c996ca4e9c8cdc5fb56793656bc95355728bf Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 19 Oct 2001 14:05:18 +0000 Subject: [PATCH] changed the way we get content-type during file upload. 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 | 7 ++-- source/mir/misc/StringUtil.java | 11 ++++++ source/mircoders/producer/ProducerStartPage.java | 2 +- .../mircoders/servlet/ServletModuleOpenIndy.java | 43 ++++++++++++++++------ 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/dbscripts/populate_mediatyp.sql b/dbscripts/populate_mediatyp.sql index 74210e3f..390953f0 100755 --- a/dbscripts/populate_mediatyp.sql +++ b/dbscripts/populate_mediatyp.sql @@ -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 diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index 54d70c62..49004c1d 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -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 diff --git a/source/mircoders/producer/ProducerStartPage.java b/source/mircoders/producer/ProducerStartPage.java index 133b698d..af3f9b57 100755 --- a/source/mircoders/producer/ProducerStartPage.java +++ b/source/mircoders/producer/ProducerStartPage.java @@ -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"; diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index ad77a2e5..8efa6d1d 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -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"); } -- 2.11.0