Resumable Large File Upload Using TUS Protocol In Go and NextJS.

Sherpalden
readytowork, Inc.
Published in
2 min readAug 7, 2022

Hello there, I am delighted that you landed here and hope you will find what you are looking for. Well, in this article, you will find the complete implementation of resumable large file upload. We will use the technologies: Go with Gin Framework for server-side implementation; NextJS for the client side; Google Cloud Storage for storing the uploaded files; and the special one — TUS Protocol.

Server-side setup

Let’s begin with the server-side setup. For the server side, we need a GCP project and a GCS bucket for storing uploaded files and I assume you have that setup yourself. Now, let’s jump right into creating an API.

Install these dependencies in your Go project.

go get "github.com/gin-contrib/cors"go get "github.com/gin-gonic/gin"go get "github.com/tus/tusd"

I have attached the code below and I suppose it is self-explanatory with descriptive comments. Besides, you can also visit the GitHub repository for the whole project setup: https://github.com/sherpalden/go-tus-api

Client-side setup

Now, let’s move into client-side implementation by creating a NextJS application with a typescript configuration. We also need to install a library: tus-js-client for implementing tus protocol. The code snippet for the client side is as follows and the code should be self-explanatory. The link to the GitHub repository is: https://github.com/sherpalden/next-tus-client

Finally a video demonstration.

References:

--

--

Sherpalden
readytowork, Inc.

The guy who sees the dream must be different from the one who lives in reality. A software engineer from Nepal.