Rename file uploaded

2014-01-24 Thread The Dude (Abides)
Hi, I'm new to clojure and am trying to rename an uploaded file with a unique identifier such as a long time stamp as follows: (defn add-timestamp [filename] (let [ext-position (.lastIndexOf filename ".") timestamp(tc/to-long (time/now))] (if (pos? ext-position) (str (.substri

Re: Rename file uploaded

2014-01-24 Thread Jarrod Swart
It works for me. I am guessing you are not passing in a string when you are calling (add-timstamp filename). Which is to say that your param 'filename' is a map not a string. If you are passing in a map of the upload information you need to grab the filename for your let: (let [ext-postion (

Re: Rename file uploaded

2014-01-24 Thread The Dude (Abides)
Hi Jarrod, I tried changing filename to string as follows (defn handle-upload [filename] (upload-file (gallery-path) (add-timestamp (str filename))) (resp/redirect "/upload")) and still got an error as: java.lang.NullPointerException My entire file code is: (ns pgapp.routes.upload (:req

Re: Rename file uploaded

2014-01-24 Thread Jarrod Swart
Well that isn't quite what I meant. In that case you are just casting what is likely the map of upload data to a string. Try this: (defn handle-upload [filename] (str filename)) Why? This will show you what type of data you receiving on upload. My guess is that it is a map containing all

Re: Rename file uploaded

2014-01-24 Thread The Dude (Abides)
Hi Jarrod, you're exactly right, filename feeds the entire map as: {:size 17401, :tempfile #, :content-type "image/jpeg", :filename "AngryBaby4.jpg"} How can feed it just the :filename portion of the map as string to the add-timestamp function? Checking that link right now. On Friday, January

Re: Rename file uploaded

2014-01-24 Thread Jarrod Swart
You need to change your timestamp function to this, my change in bold: (defn add-timestamp [filename] (let [ext-position (.lastIndexOf *(:filename filename)* ".") timestamp(tc/to-long (time/now))] (if (pos? ext-position) (str (.substring filename 0 ext-position) "-" t

Re: Rename file uploaded

2014-01-24 Thread Jarrod Swart
I'm sorry I glossed over your code. Leave (add-timestamp) the same but do this: (defn handle-upload [filename] (upload-file (gallery-path) (add-timestamp *(:filename filename)*)) (resp/redirect "/upload")) On Saturday, January 25, 2014 12:36:45 AM UTC-5, The Dude (Abides) wrote: > > Hi Jarrod

Re: Rename file uploaded

2014-01-24 Thread The Dude (Abides)
Hi Jarrod, thanks for your help. I tried that but got a java.lang.NullPointerException error again. I tried the code without the add-timestamp and still get the java.lang.NullPointerException When I try it as just :filename filename it does in fact show only the file name. So not sure why

Re: Rename file uploaded

2014-01-25 Thread Jarrod Swart
Nothing sticks out, but a NullPointerException is something I most commonly get as a result of an incorrect file path. Things I would do: 1. Make sure that (gallery-path) actually exists or is writable. 2. I would do (POST "/upload" [file] (println file) (handle-upload file))), to inspect what

Re: Rename file uploaded

2014-01-25 Thread The Dude (Abides)
Thanks for the feedback Jarrod, the gallery-path did exist because I was able to upload files without renaming them and I saw the map with keys per your tip. I just wasn't familiar enough with the plumbing in noir.io or the language as I finally had the time to spend a week getting into clojure

Re: Rename file uploaded

2014-01-25 Thread Jarrod Swart
Awesome, glad you got it working. I highly recommend: http://pragprog.com/book/dswdcloj/web-development-with-clojure, for step by step Web Dev in Clojure. Reading through it got me up to speed really quickly as far as project structure, common libs and practices, etc. On Saturday, January 25