Forgot the code:
Some needed import:

import _root_.scala.xml.{NodeSeq, Text, Group}

The xhtml:

    <lift:snippet type="data:upload" form="post" multipart="true">
        <choose:post>
            <p>
            File name: <ul:file_name/><br />
            MIME Type: <ul:mime_type/><br />
            File length: <ul:length/><br />
            MD5 Hash: <ul:md5/><br />
            </p>
        </choose:post>

        <choose:get>
            Select a file to upload: <ul:file_upload/><br />
            <input type="submit" value="Upload File"/>
        </choose:get>
    </lift:snippet>


The snippet:

    private object theUpload extends RequestVar[Box[FileParamHolder]]
(Empty)

    def upload(xhtml: NodeSeq): NodeSeq =
    if (S.get_?) bind("ul", chooseTemplate("choose", "get", xhtml),
                      "file_upload" -> fileUpload(ul => theUpload(Full
(ul))))
    else {

        bind("ul", chooseTemplate("choose", "post", xhtml),//else:
It's a POST
             "file_name" -> theUpload.is.map(v => Text(v.fileName)),
             "mime_type" -> theUpload.is.map(v => Box.legacyNullTest
(v.mimeType).map(Text).openOr(Text("No mime type supplied"))), // Text
(v.mimeType)),
             "length" -> theUpload.is.map(v => Text
(v.file.length.toString)),
             "md5" -> theUpload.is.map(v => Text(hexEncode(md5
(v.file))))
        )
    }




On Jul 13, 8:24 pm, kjetilge <[email protected]> wrote:
> Thanks, I've now taken the upload part of the code and integrated it
> in to my learning project. I can now choose a file for upload, the
> file is uploaded but not stored, after the upload is complete the page
> displays the file details. Very good :-)
> I'm planning to build a video training site. I will need to upload
> images and video.
>
> I think perhaps it's a good idea to keep the images in the database
> and the video as a file. I have a similar site developed in rails
> (www.fagfilm.no- no that's not what you think it is...) that stores
> the video on Amazoon S3. So actually i'd like to be able to upload the
> video to S3.
>
> On Jul 13, 6:12 pm, Timothy Perrett <[email protected]> wrote:
>
>
>
> > Hi there again,
>
> > Please keep discussions strictly on list - its the only way for everyone to
> > benefit from the conversation we have and interject where they feel they
> > want to. This means you get more input from more sources and doesn't mail
> > people directly (my personal preference).
>
> > If your interested in how one uploads a file in Lift, checkout the sample
> > application here:http://to.ly/jtz
>
> > Do you have any experience of developing with Java? Which would you rather,
> > save to database, or save to file? The impl is quite different for each.
>
> > Cheers, Tim
>
> > > On 13/07/2009 16:20, "kjetilge" <[email protected]> wrote:
> > > Thanks. Well, it helps, I've learned something new, but what would
> > > really be useful is a link or two to sample code showing how this is
> > > done in real life. I've just recently finished reading Programming in
> > > Scala and most of the Lift Book and I cant remember anything from this
> > > text that would directly help me with persisting an Array[Byte] to a
> > > database or as a file.
>
> > > I guess I could use Scala.io or java.io for saving files perhaps ? But
> > > WHERE should the files go ? I come from Rails where finding out these
> > > things cost 30 sec googling. I must say that finding relevant
> > > tutorials and (working) sample code for basic tasks in Lift is very
> > > hard, even for a determined wannabe Lift developer like myself :-)
>
> > > On 13/07/2009 14:39, "Timothy Perrett" <[email protected]> wrote:
>
> > > Hi there,
>
> > > Generally speaking, that's now how uploading in lift works - any given 
> > > upload
> > > goes into a FileParamHolder object then you can persist it however you 
> > > would
> > > like (filesystem, database etc) as your essentially left with 
> > > Array[Byte]...
>
> > > Does that help?
>
> > > Cheers, Tim
>
> > > On 13/07/2009 14:26, "kjetilge" <[email protected]> wrote:
>
> > >> I'm a newbie and I'm having troble with finding a hint in the Liftbook
> > >> on how to set the path for an upload folder in Lift. In the manual
> > >> there is an example using a variable called tmpDir. Problem is, there
> > >> is no explanation for what the value of this variable should be. Apart
> > >> from that, I've at least managed to load an image in the browser after
> > >> defining a pictures folder in main/resources/toserve/pictures by
> > >> using:
> > >>         ResourceServer.allow {
> > >>             case "pictures" :: _ => true
> > >>         }
> > >> Then I can do: <img src="/classpath/pictures/sykkel.jpg" alt="Sykkel"/
> > >>> , and it works :-)
> > >> But when I set the value tmpDir="/classpath/pictures/" and try to
> > >> upload a file I get:
> > >> java.io.FileNotFoundException: /classpath/pictures/Lift Book.pdf
>
> > >> I'm obviously doing something terribly wrong. Does anybody know how to
> > >> do this ?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to