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 24, 2014 9:05:35 PM UTC-8, Jarrod Swart wrote:
>
> 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 the data about the file upload.
>
> Following this: 
> http://www.luminusweb.net/docs/static_resources.md#handling_file_uploads 
> should 
> help.
>
> In short: you still don't have the right kind of data going into your 
> function.  Change your handle-upload to the above and verify that you are 
> getting the filename alone in your (let [filename (...)] ...) binding.
>
> Hope that helps.
>
> On Friday, January 24, 2014 11:28:00 PM UTC-5, The Dude (Abides) wrote:
>>
>> 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 
>>   (: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))
>>
>> (use 'ring.middleware.params
>>         'ring.middleware.multipart-params)
>>
>> (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 (str filename)))
>>  (resp/redirect "/upload"))
>>
>> (defroutes myapp-routes
>>   (GET "/upload" [info] (upload-page {:info info}))
>>   (POST "/upload" [file] (handle-upload file)))
>>
>> I changed filename to (str filename) in the handle-upload function, but 
>> still no dice :(
>>
>> The :refer [galleries gallery-path thumb-uri thumb-prefix 
>> unique-prefix]]) are just references to file paths in util.clj vs 
>> hardcoding them.
>>
>> I got productive with clojure ref routes, sessions, views with selmer and 
>> queries either raw or with korma all easy peasy. However this one thing, 
>> this file upload issue has thrown me for a loop for 3 days now :) It is the 
>> bane of my existence right now :) 
>>
>> If I can get a handle on it, am considering creating a library to make 
>> this easier akin to file upload plugins in ruby world like carrier-wave. 
>> Thanks for any pointers on what I'm doing wrong with the above code.
>>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to