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.