I think you've gotten the wrong idea about [returnBlob]. It operates in the style of exceptions, ending the transaction with the given result. It's not a normal function return, so you can't use it pass a blob from one part of your program to another. Also, it definitely doesn't generate strings.

Somewhat intentionally, Ur/Web currently does not provide a way to introspect into a blob, without using the FFI. It would take some thought on what the right API would be. In my applications that involve CSV import, I have their content pasted into textboxes.

On 02/19/2017 10:11 AM, Marko Schütz Schmuck wrote:
I'm confused about the use of returnBlob.

I was looking through the existing urweb demos to see how I could
access the data in a blob of mime type "text/plain" as a string.
Eventually, I want to import into a table from a CSV file the user
uploads.

I hoped that returnBlob used in a transaction string could achieve
this. So I modified demo/upload.ur to

fun echo (r : {File : file}) : transaction string =
   if blobSize (fileData r.File) > 100000 then
       return "Whoa!  That one's too big."
   else
       returnBlob (fileData r.File) (blessMime (fileMimeType r.File))

fun echoLength (r : {File : file}) : transaction page =
     s <- echo r ;
     return <xml>{[String.length s]}</xml>

fun main () : transaction page
   = return <xml><body>
   <h1>The Amazing File Echoer!</h1>

   <form>Upload a file: <upload{#File}/> <submit action={echoLength}/></form>
</body></xml>

This compiles and runs, and when I supply a file longer than 100000 I
get the expected page with the result 26, but to my surprise a shorter
file results in a page with the content of the file not it's length.

I'd really appreciate some help.

Thanks in advance and best regards,

Marko

_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to