This time we well upgrade our app with picture uploading feature.
There is 2 ways to work with pictures
Pluses and minuses of first way:
Second way:
Mostly using remote service is good for small apps or for prototypes that handles 100 to 1000 pics a day. Maybe things will change soon but comparing and analysing these two ways is topic of another article.
Short list of todos.
I will use filepicker for pictures handling. Nice and easy to use service. We upload picture to service and get back url with uploaded picture. You can apply some restrictions to uploading like maximum size, weight ( in MB), convert picture or not.
So in our app we will upload and convert picture and then store it to S3 Amazon bucket. Mostly in your projects you will store images at the services like S3 because it’s convinient fast and reliable. Also we need to use remote server for static files for heroku - heroku doesn’t allow you store static files (like pictures) on the service.
Upload picture and display it under title author fields.
To make filepicker service work you need filepicker.js library, you can take it here.
Include it with: (include-js “/js/filepicker.js”) in common.clj file. We need some html code to handle uploading and some cljs to convert and store our picture to localhost. Here is the HTML code:
CLJS code: Upload picture via widget, convert it to 100px and store to S3, insert url string in hidden field:
Store and convert functions check at github repo.
Important notice! You need to update your filepicker account with Amazon S3 service credentials.
Submit book info and reload books list all with ajax calls
Here is cljs code for that:
Update picture of the book
Notice here as we use this-as macro. If we click a link then we need this to get attribues of the link our macro this-as plays role of this. You can name this as you like
(fn[e](this-as bid (update-img bid e)))).
That’s it we are done with S3 uploading. As usual you can find all code at github.