Node Tutorial
#
Building a Simple Image Server with Deta Drive#
SetupTo get started, create a directory image-server
and change the current directory into it.
Before we begin, let's install all the necessary dependencies for this project.
In this tutorial, we are using express
to build our server, and express-fileupload
allows us to access the uploaded file data.
To configure the app, import the dependencies and instantiate drive in index.js
We have everything we need to 🚀
#
Uploading ImagesFirst, we need to render a HTML snippet to display the file upload interface.
We'll expose a function that renders the HTML snippet on the base route /
We are simply rendering a HTML form that sends a HTTP POST
request to the route /upload
with file data.
Let's complete file upload by creating a function to handle /upload
We can access the image details from req
and store it in Drive.
#
Downloading ImagesTo download images, we can simply use drive.get(name)
If we tie a GET
request to the /download
path with a param giving a name (i.e /download/space.png
), we can return the image over HTTP.
#
Running the serverTo run the server locally, navigate to the terminal in the project directory (image-server
) and run the following command:


#
IssuesIf you run into any issues, consider reporting them in our Github Discussions.