Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Upload field on a lift screen
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tareq Abedrabbo  
View profile  
 More options Oct 18 2011, 7:19 am
From: Tareq Abedrabbo <tareq.abedra...@gmail.com>
Date: Tue, 18 Oct 2011 04:19:55 -0700 (PDT)
Local: Tues, Oct 18 2011 7:19 am
Subject: Upload field on a lift screen
Hi all,

I'm wondering how to create a file upload field on a Lift Screen. I
can see that Lift Screen checks for upload fields and that Field has
an uploadField_? property but I'm not clear on whether a call to the
field method can render a file upload field and what the default value
would be in this case.
Thanks in advance for your help.

Tareq


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Pollak  
View profile  
 More options Oct 18 2011, 2:38 pm
From: David Pollak <feeder.of.the.be...@gmail.com>
Date: Tue, 18 Oct 2011 11:38:52 -0700
Local: Tues, Oct 18 2011 2:38 pm
Subject: Re: [Lift] Upload field on a lift screen

You have to create a custom field.  Here's a Screen that does an upload:

import net.liftweb._
import http._
import common._
import scala.xml._

class UploadScreen extends LiftScreen {
  override protected def hasUploadField = true

  val name = field("Name", "")
  val file = makeField[Array[Byte], Nothing]("File", new Array[Byte](0),
    field => SHtml.fileUpload(fph => field.set(fph.file)),
    NothingOtherValueInitializer)

  def finish() {
    S.notice("Thanks for uploading a file of " + file.get.length + " bytes
")
  }

}

Here's a running example:
https://github.com/dpp/starting_point/tree/screen_file_upload

On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo
<tareq.abedra...@gmail.com>wrote:

--
Lift, the simply functional web framework http://liftweb.net
Simply Lift http://simply.liftweb.net
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Readman  
View profile  
 More options Sep 18 2012, 1:27 pm
From: Readman <gaoy...@gmail.com>
Date: Tue, 18 Sep 2012 10:27:25 -0700 (PDT)
Local: Tues, Sep 18 2012 1:27 pm
Subject: Re: [Lift] Upload field on a lift screen

Hey David,
Thanks for posting this example.
However, what is the upload directory in this example? I can not see any
file in folder, when i uploaded a file

Chenguang He


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Olek Swirski  
View profile  
 More options Sep 18 2012, 3:05 pm
From: Olek Swirski <olekswir...@gmail.com>
Date: Tue, 18 Sep 2012 21:05:41 +0200
Local: Tues, Sep 18 2012 3:05 pm
Subject: Re: [Lift] Upload field on a lift screen

file goes to whatever is temp dir for your app,
which may quite possibly be /tmp
in that case, file may quickly be cleaned by OS,
so then you would need to keep reference
to FileParamHolder and move it elsewhere or
maybe setting tmp dir for your app to different
value with System.setProperty or by giving
command line arg to java

On 18/09/12 19:27, Readman wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Olek Swirski  
View profile  
 More options Sep 18 2012, 3:11 pm
From: Olek Swirski <olekswir...@gmail.com>
Date: Tue, 18 Sep 2012 21:11:24 +0200
Local: Tues, Sep 18 2012 3:11 pm
Subject: Re: [Lift] Upload field on a lift screen

oh, I forgot. by default file will be loaded into the memory
and never appear on the hard drive. then fph is your
only handle to do something with it before it disappears.

to get on disk file you need to call this in your boot:
     /* store uploads as files on disk */
     LiftRules.handleMimeFile = OnDiskFileParamHolder.apply
you may also need these:
     /* set max total upload size */
     LiftRules.maxMimeSize = 1024 * 1024 * 32
     /* set max per-file upload size */
     LiftRules.maxMimeFileSize = 1024 * 1024 * 32;

also, that file will have some random name, because
otherwise there could easily be name clash if someone
uploads two same named files to your application. you
may restore original upload name from fph.fileName

On 18/09/12 21:05, Olek Swirski wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chenguang He  
View profile  
 More options Sep 18 2012, 4:17 pm
From: Chenguang He <gaoy...@gmail.com>
Date: Tue, 18 Sep 2012 15:16:57 -0500
Local: Tues, Sep 18 2012 4:16 pm
Subject: Re: [Lift] Upload field on a lift screen

Uhm..
Sorry, i still don't know how to upload file to a  specific folder.
Does fph store the file or the location in memory?

Chenguang He

On Sep 18, 2012, at 2:11 PM, Olek Swirski wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Olek Swirski  
View profile  
 More options Sep 18 2012, 4:24 pm
From: Olek Swirski <olekswir...@gmail.com>
Date: Tue, 18 Sep 2012 22:24:42 +0200
Local: Tues, Sep 18 2012 4:24 pm
Subject: Re: [Lift] Upload field on a lift screen

If you set up
LiftRules.handleMimeFile = OnDiskFileParamHolder.apply
then, the the file will be accessible as fph.localFile
if you use InMemFileParamHolder (which I think is default)
then, you get file bytes via
val file: Array[Byte]
and need to write them yourself somewhere, which can be
done with java.io or java.nio (you may need to read javadoc
for these, which are very comprehensive)

On 18/09/12 22:16, Chenguang He wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Olek Swirski  
View profile  
 More options Sep 18 2012, 4:31 pm
From: Olek Swirski <olekswir...@gmail.com>
Date: Tue, 18 Sep 2012 22:31:49 +0200
Local: Tues, Sep 18 2012 4:31 pm
Subject: Re: [Lift] Upload field on a lift screen

you need to have java 7 (not 6 or earlier) to use nio package
docs are here:
http://docs.oracle.com/javase/7/docs/api/java/io/package-summary.html
http://docs.oracle.com/javase/7/docs/api/java/nio/package-summary.html
there is a nice io tutorial here:
http://docs.oracle.com/javase/tutorial/essential/io/index.html

On 18/09/12 22:24, Olek Swirski wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chenguang He  
View profile  
 More options Sep 18 2012, 6:51 pm
From: Chenguang He <gaoy...@gmail.com>
Date: Tue, 18 Sep 2012 17:51:08 -0500
Local: Tues, Sep 18 2012 6:51 pm
Subject: Re: [Lift] Upload field on a lift screen

Thank you.
It works!
Chenguang He

On Sep 18, 2012, at 3:31 PM, Olek Swirski wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »