The file not found error may be because the directory doesn't exist. Try 
calling file.mkdirs first.

-------------------------------------
Neil.Lv<anim...@gmail.com> wrote:



  I want to save the images to a directory, because this images will
be used in the flash params.

  This file path will be used in the javascript code .
###
  var imag=new Array();
  imag[3]="/images/01.jpg";
###

Cheers,
  Neil

On Nov 15, 12:05 pm, "Neil.Lv" <anim...@gmail.com> wrote:
> Hi all,
>
>   Thanks for your tips, and I have some silly question about this.
>
>   1:)  a directory that's not part of the app's exploded WAR file
>
>   The direcotry tree like this, and Where is i can create a well
> defined directory
> that's not part of the app's exploded WAR file ? I'm not        familiar
> with this.
>
> ###
> demo
>   --src
>     --main
>       --resources
>         --i18n
>         --props
>       --scala
>       --webapp
>     --test
>   --target
> ###
>
>   2:) If I store images to the RDBMS, and how can it be shown in the
> webpage ?
> ###
>    FileParamHolder(_, mime, name, data)
>    ....
>    item.receipt(data).receiptMime(mime)   // ( Array[Byte] that saved
> into database )
> ###
>
>   :)
>
>   Thanks very much !
>
> Cheers,
>   Neil
>
> On Nov 15, 5:43 am, David Pollak <feeder.of.the.be...@gmail.com>
> wrote:
>
> > On Sat, Nov 14, 2009 at 10:25 AM, Neil.Lv <anim...@gmail.com> wrote:
>
> > > Tim,
>
> > >  haha, yeah.
>
> > >  I use this code to get the images folder(the full path) of the app.
>
> > >  LiftRules.getResource("/images/").open_!.toString.substring(6)
> > > (The code is so redundant !)
> > >    -> G:\project\demo\src\main\webapp\images\
>
> > You cannot rely on being able to write to a directory in an application.
> > This is dependent on how the specific web app container handles things, but
> > I would strongly suggest you write images to a directory that's not part of
> > the app's exploded WAR file.  And "strongly" is a very weak description of
> > how forceful I'm being about this.  This kind of code may change behaviour
> > between your dev box and production, between versions of your app container.
>
> > If you want to store images to serve, either use a well defined directory
> > outside your WAR file or put stuff in your RDBMS or put stuff up on Amazon
> > (like Twitter does with images).  Amazon has much better infrastructure for
> > dealing with serving static content than just about anyone else.
>
> > >  :)
>
> > >  Thank you very much !
>
> > > Cheers,
> > >   Neil
>
> > > On Nov 15, 1:50 am, Timothy Perrett <timo...@getintheloop.eu> wrote:
> > > > Hmm, I guess you must be new to the JVM - you cant write a file inside a
> > > WAR file; it does not work like that.
>
> > > > You'll need to write to a fully qualified path (as per my example).
>
> > > > Cheers, tim
>
> > > > On 14 Nov 2009, at 17:34, Neil.Lv wrote:
>
> > > > >  It show this error message:
>
> > > > >  ERROR - java.io.FileNotFoundException: \images\003.jpg
>
> > > > > #########  this is the code
>
> > > > > val receiptOk = fileHolder match {
> > > > > case Full(FileParamHolder(_, null, _, _)) => true
> > > > > case Full(FileParamHolder(_, mime, name, data))
> > > > >  if mime.startsWith("image/") => {
> > > > >    var buff = new java.io.BufferedInputStream(new ByteArrayInputStream
> > > > > (data))
> > > > >    try {
> > > > >     var fos = new java.io.FileOutputStream(new File("/images/" +
> > > > > name))
> > > > >     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
> > > > >    true
> > > > >  }
> > > > > case Full(_) => {
> > > > > S.error(S.??("invalid.receipt.attachment"))
> > > > > false
> > > > > }
> > > > > case _ => true
> > > > > }
>
> > > > > #########
>
> > > > >   Maybe this code is wrong ?
>
> > > > >   new File("/images/" + name)
>
> > > > >   I want to save it in the main\webapp\images\  folder.
> > > > >     -> main\webapp\images\ 003.jpg
>
> > > > >   :)
>
> > > > > Cheers,
> > > > >  Neil
>
> > > > > On Nov 15, 12:23 am, Timothy Perrett <timo...@getintheloop.eu> wrote:
> > > > >> 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" <anim...@gmail.com> 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" <anim...@gmail.com> 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
>
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > Follow me:http://twitter.com/dpp
> > Surf the harmonics


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

Reply via email to