This is the part 2 of 2 in DropzoneJS + Go series.
In this tutorial, we will show you how to display existing files on the server when using DropzoneJS and Go. This tutorial is based on How to build a file upload form using DropzoneJS and Go. Make sure you have read it before proceeding to content in this tutorial.
Install the go package “github.com/nfnt/resize” with go get github.com/nfnt/resize
, we need it to create thumbnails.
In previous tutorial. We have already set up a proper working DropzoneJs upload form. There is no additional file needed for this tutorial. What we need to do is to make some modifications to file below:
Let us get started!
In previous tutorial. All “/upload” does is to store uploaded files to the server directory “./public/uploads”. So we need to add a piece of code to retrieve stored files’ information (name and size), and return it in JSON format.
Copy the content below to “main.go”. Read comments for details.
Copy content below to “./views/upload.html”. We will go through modifications individually.
Open the terminal at the current project’s directory and execute:
$ go run main.goNow listening on: http://localhost:8080Application started. Press CTRL+C to shut down.
If you have done it successfully. Now go and upload some images and reload the upload page. Already uploaded files should auto display in Dropzone area.
Hopefully this simple tutorial helped you with your development. If you like my post, please follow me on Twitter and help spread the word. I need your support to continue.
Gerasimos Maropoulos (@MakisMaropoulos) | Twitter_The latest Tweets from Gerasimos Maropoulos (@MakisMaropoulos). That #golang guy. Self-taught Developer with 10+ years…_twitter.com
I like the visual effects when I click the clap button more than once, do you? It’s simple: just click the clap button. If you feel strongly, click it more (or just hold it down).