# HG changeset patch # User Adam Chlipala # Date 1240685236 14400 # Node ID b302b6e35f93fae0ffd00b70b14b8a7ee3b87949 # Parent 4bb7e1c0550a4a734c872750c16937a384350268 Add MIME type to file diff -r 4bb7e1c0550a -r b302b6e35f93 include/types.h --- 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; diff -r 4bb7e1c0550a -r b302b6e35f93 include/urweb.h --- 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); diff -r 4bb7e1c0550a -r b302b6e35f93 lib/ur/basis.urs --- 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] diff -r 4bb7e1c0550a -r b302b6e35f93 src/c/driver.c --- 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 diff -r 4bb7e1c0550a -r b302b6e35f93 src/c/urweb.c --- 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; } diff -r 4bb7e1c0550a -r b302b6e35f93 tests/blob.ur --- 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