Neil,
Try something like:
var buff = new java.io.BufferedInputStream(input)
try {
var fos = new java.io.FileOutputStream(new File("/some/root/
filepath/" + image_hash_filename))
var in = 0
do {
in = buff.read()
if (in != -1){
fos.write(in)
}
} while((in != -1))
fos = null
in = 0
} catch {
case e => Log.error(e)
} finally {
buff.close()
}
buff = null
}
In my case, I had the data as an input stream - manipulate this code
to take it however you need.
Cheers, Tim
On Nov 14, 7:55 am, "Neil.Lv" <[email protected]> wrote:
> Here is some code , but it's wrong!
>
> --> java.io.FileNotFoundException: \images\1.jpeg
>
> if mime.startsWith("image/") => {
> try{
> var file: File = new File("/images/1.jpeg");
> var fos:FileOutputStream = new FileOutputStream(file);
> fos.write(data)
> } catch {
> case e => println("exception: " + e)
> }
> e.receipt(data).receiptMime(mime)
> true
> }
>
> I don't know how to write the code in the try catch statement.
>
> Does anyone can help me ?~
>
> Thanks very much !
>
> Cheers,
> Neil
>
> On Nov 14, 1:58 pm, "Neil.Lv" <[email protected]> wrote:
>
>
>
> > Hi all,
>
> > How to save the uploaded image into the folder via fileUpload in
> > Lift?
>
> > I don't want to save it in the database, the example code in the
> > Pocketchangeapp
>
> > ###
> > val receiptOk = fileHolder match {
> > case Full(FileParamHolder(_, null, _, _)) => true
> > case Full(FileParamHolder(_, mime, _, data))
> > if mime.startsWith("image/") => {
> > // How can i save the data into a image in the folder.
> > e.receipt(data).receiptMime(mime)
> > true
> > }
> > case Full(_) => {
> > S.error("Invalid receipt attachment")
> > false
> > }
> > case _ => true
> > }
> > ###
>
> > To save the image into the webapp\images folder, and it's shown
> > just use this link:
> > /images/img1.jpg
>
> > Thanks for any suggestion!
>
> > Cheers,
> > Neil
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---