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.
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 ") }
> 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.
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
> 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 > ") > } > }
> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo <tareq.a...@gmail.com<javascript:> > > wrote:
>> 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.
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
> 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
> On Tuesday, October 18, 2011 1:38:52 PM UTC-5, David Pollak wrote:
> You have to create a custom field. Here's a Screen that does an
> upload:
> 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 ")
> }
> }
> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo
> <tareq.a...@gmail.com <javascript:>> wrote:
> 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.
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
> 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:
>> 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
>> On Tuesday, October 18, 2011 1:38:52 PM UTC-5, David Pollak wrote:
>> You have to create a custom field. Here's a Screen that does an
>> upload:
>> 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 ")
>> }
>> }
>> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo
>> <tareq.a...@gmail.com <javascript:>> wrote:
>> 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.
> 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:
>> 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:
>>> 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
>>> On Tuesday, October 18, 2011 1:38:52 PM UTC-5, David Pollak wrote:
>>> You have to create a custom field. Here's a Screen that does an upload:
>>> 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 ")
>>> }
>>> }
>>> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo <tareq.a...@gmail.com> wrote:
>>> 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.
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)
> 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:
>> 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:
>>> 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:
>>>> 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
>>>> On Tuesday, October 18, 2011 1:38:52 PM UTC-5, David Pollak wrote:
>>>> You have to create a custom field. Here's a Screen that does
>>>> an upload:
>>>> 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 ")
>>>> }
>>>> }
>>>> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo
>>>> <tareq.a...@gmail.com <javascript:>> wrote:
>>>> 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.
> 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:
>> 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:
>>> 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:
>>>> 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:
>>>>> 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
>>>>> On Tuesday, October 18, 2011 1:38:52 PM UTC-5, David Pollak wrote:
>>>>> You have to create a custom field. Here's a Screen that does
>>>>> an upload:
>>>>> 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 ")
>>>>> }
>>>>> }
>>>>> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo
>>>>> <tareq.a...@gmail.com <javascript:>> wrote:
>>>>> 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.
>> 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:
>>> 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:
>>>> 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:
>>>>> 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:
>>>>>> 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
>>>>>> On Tuesday, October 18, 2011 1:38:52 PM UTC-5, David Pollak wrote:
>>>>>> You have to create a custom field. Here's a Screen that does an upload:
>>>>>> 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 ")
>>>>>> }
>>>>>> }
>>>>>> On Tue, Oct 18, 2011 at 4:19 AM, Tareq Abedrabbo <tareq.a...@gmail.com> wrote:
>>>>>> 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.