[Ur] returnBlob behavior?

Marko Schütz Schmuck MarkoSchuetz at web.de
Sun Feb 19 10:11:17 EST 2017


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP Digital Signature
URL: <http://www.impredicative.com/pipermail/ur/attachments/20170219/104c06e5/attachment.sig>


More information about the Ur mailing list