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 you are capturing on the route destructure.
Again that NullPointerException means that the code is expecting some
object, but you are passing in null. As I stated 99% of the time I get
that error in Clojure it is due to an improper path/filename/resource. So
I would start checking any part of the code that reads/writes to files on
the hard drive. Make sure they have the proper permissions, and that the
paths look write.
I'm sure this seems like stuff you know or may have tried, but I found when
getting started with Clojure that everything was so new in general that it
broke my ability to "debug". I had to learn how to troubleshoot all over
again.
Good luck!
On Saturday, January 25, 2014 2:10:57 AM UTC-5, The Dude (Abides) wrote:
>
> 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 this is being so tricky, rest of clojure stuff has been
> very straightforward, this one file load issue is more boilerplate than I'm
> used to in ruby or coldfusion, and it just seems v tricky as the error
> codes are not yielding the source of the problem or maybe I don't yet know
> how to interpret them properly.
>
> It doesn't seem the problem is in the "add-timestamp" function, as the
> operation croaks even before getting there when I isolate it to just
> 'handle-upload' function without ever calling the add-timestamp function.
>
> I'll post the entire code again just in case you may spot where the error
> maybe. Perhaps the problem is in the libs I'm requiring or importing? Again
> thanks for taking a look, much appreciated.
>
> (ns pgapp.routes.upload
> (:require [compojure.core :refer [defroutes GET POST]]
> [pgapp.views.layout :as layout]
> [noir.io :refer [upload-file resource-path]]
> [noir.session :as session]
> [noir.response :as resp]
> [noir.util.route :refer [restricted]]
> [clojure.java.io :as io]
> [ring.util.response :refer [file-response]]
> [taoensso.timbre :refer [error]]
> [pgapp.models.db :as db]
> [clj-time.core :as time]
> [clj-time.coerce :as tc]
> [pgapp.util
> :refer [galleries gallery-path thumb-uri thumb-prefix
> unique-prefix]])
> (:import [java.io File FileInputStream FileOutputStream]
> javax.imageio.ImageIO))
>
> (defn upload-page [info]
> (layout/render "upload.html"))
>
> (defn add-timestamp [filename]
> (let [ext-position (.lastIndexOf filename ".")
> timestamp (tc/to-long (time/now))]
> (if (pos? ext-position)
> (str (.substring filename 0 ext-position)
> "-" timestamp (.substring filename ext-position))
> (str filename "-" timestamp))))
>
> (defn handle-upload [filename]
> (upload-file (gallery-path) (add-timestamp (:filename filename)))
> (resp/redirect "/upload"))
>
> (defroutes upload-routes
> (GET "/upload" [info] (upload-page {:info info}))
> (POST "/upload" [file] (handle-upload file)))
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.