changeset 740:b302b6e35f93

Add MIME type to file
author Adam Chlipala <adamc@hcoop.net>
date Sat, 25 Apr 2009 14:47:16 -0400
parents 4bb7e1c0550a
children f7e2026dd5ae
files include/types.h include/urweb.h lib/ur/basis.urs src/c/driver.c src/c/urweb.c tests/blob.ur
diffstat 6 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/include/types.h	Sat Apr 25 14:35:49 2009 -0400
+++ b/include/types.h	Sat Apr 25 14:47:16 2009 -0400
@@ -29,7 +29,7 @@
 } uw_Basis_channel;
 
 typedef struct uw_Basis_file {
-  uw_Basis_string name;
+  uw_Basis_string name, type;
   uw_Basis_blob data;
 } uw_Basis_file;
 
--- a/include/urweb.h	Sat Apr 25 14:35:49 2009 -0400
+++ b/include/urweb.h	Sat Apr 25 14:47:16 2009 -0400
@@ -163,5 +163,6 @@
 uw_Basis_string uw_Basis_sigString(uw_context, uw_unit);
 
 uw_Basis_string uw_Basis_fileName(uw_context, uw_Basis_file);
+uw_Basis_string uw_Basis_fileMimeType(uw_context, uw_Basis_file);
 uw_Basis_blob uw_Basis_fileData(uw_context, uw_Basis_file);
 
--- a/lib/ur/basis.urs	Sat Apr 25 14:35:49 2009 -0400
+++ b/lib/ur/basis.urs	Sat Apr 25 14:47:16 2009 -0400
@@ -516,6 +516,7 @@
 
 type file
 val fileName : file -> option string
+val fileMimeType : file -> string
 val fileData : file -> blob
 
 val upload : formTag file [] [Value = string, Size = int]
--- a/src/c/driver.c	Sat Apr 25 14:35:49 2009 -0400
+++ b/src/c/driver.c	Sat Apr 25 14:47:16 2009 -0400
@@ -393,7 +393,7 @@
             part += boundary_len;
 
             if (filename) {
-              uw_Basis_file f = {filename, {part_len, after_sub_headers}};
+              uw_Basis_file f = {filename, type, {part_len, after_sub_headers}};
 
               uw_set_file_input(ctx, name, f);
             } else
--- a/src/c/urweb.c	Sat Apr 25 14:35:49 2009 -0400
+++ b/src/c/urweb.c	Sat Apr 25 14:47:16 2009 -0400
@@ -632,7 +632,7 @@
   case UNSET:
     {
       char *data = uw_malloc(ctx, 0);
-      uw_Basis_file f = {"", {0, data}};
+      uw_Basis_file f = {NULL, "", {0, data}};
       return f;
     }
   case FIL:
@@ -2128,6 +2128,10 @@
   return f.name;
 }
 
+uw_Basis_string uw_Basis_fileMimeType(uw_context ctx, uw_Basis_file f) {
+  return f.type;
+}
+
 uw_Basis_blob uw_Basis_fileData(uw_context ctx, uw_Basis_file f) {
   return f.data;
 }
--- a/tests/blob.ur	Sat Apr 25 14:35:49 2009 -0400
+++ b/tests/blob.ur	Sat Apr 25 14:47:16 2009 -0400
@@ -1,9 +1,10 @@
 sequence s
-table t : { Id : int, Nam : option string, Data : blob, Desc : string }
+table t : { Id : int, Nam : option string, Data : blob, Desc : string, Typ : string }
 
 fun save r =
     id <- nextval s;
-    dml (INSERT INTO t (Id, Nam, Data, Desc) VALUES ({[id]}, {[fileName r.Data]}, {[fileData r.Data]}, {[r.Desc]}));
+    dml (INSERT INTO t (Id, Nam, Data, Desc, Typ)
+         VALUES ({[id]}, {[fileName r.Data]}, {[fileData r.Data]}, {[r.Desc]}, {[fileMimeType r.Data]}));
     main ()
 
 and main () = return <xml><body>