27 Feb 2014, 03:28
Generic-user-small

Richard Burgis (6 posts)

When you upload a file it is stored with the original name. If that name contains spaces they are also in the file in the gallery. Looking at the noir documentation there is not an immediately obvious way to change this name during the upload and storage.

This is a problem because the web page can no longer find the file.

When displaying the file image-uri converts the name using url-encode. This puts a ‘+’ in place of the space. At which point it can no longer find the file. Assuming that there is a good reason to use url-encode, how can we change the name when it is uploaded?

All I’ve found is copying the file and then deleting the original. This seems unreasonable. Is there a better way?

Thank you Rich

01 Mar 2014, 14:35
Profile_pic_pragsmall

Dmitri Sotnikov (42 posts)

Hi Rich,

The easiest way would be to simply update the filename of the file before you save it. For example, you could do this in the “/upload” route:

(defn format-filename [filename]
  (clojure.string/replace filename #" " "_"))

(defroutes upload-routes
  ...
  (POST "/upload" [file]
        (restricted (handle-upload (update-in file [:filename] format-filename))))
  ...)
01 Mar 2014, 16:19
Generic-user-small

Richard Burgis (6 posts)

So, the argument to handle-upload is actually the file object (or map) not just the file name. So changing the name in the map doesn’t keep the upload-file function from finding it.

That is very helpful.

Thank you

  You must be logged in to comment