Hi guys! Today I bring you a package that allows you to upload
, list
and delete
files with various cloud services Cloudinary, Amazon S3
β€οΈ Follow me
βοΈ Setup
Before you start using Filesrocket you need to set up a simple Node.js project
Create project
mkdir my-filesrocket-app
cd my-filesrocket-app
code .
Initialize project
npm i typescript ts-node -g
npm init -y
tsc --init --target es2018
π Get started
But before continuing you need to create a cloudinary account. If you don't have an account yet, click here and follow all the steps.
To start using Filesrocket it is necessary to install the dependencies.
npm i express filesrocket filesrocket-cloudinary
npm i @types/express -D
Create src/index.ts
file and copy the following content
import express from "express";
import { Filesrocket } from "filesrocket";
import { CloudinaryFileService } from "filesrocket-cloudinary";
// Initialize Filesrocket
const filesrocket = new Filesrocket();
// Setting service.
const service = new CloudinaryFileService({
pagination: { default: 15, max: 50 },
cloud_name: "<Your CLOUDNAME>",
api_key: "<Your API KEY>",
api_secret: "<Your API SECRET>"
});
// Register your service.
filesrocket.register("cloudinary", service);
const app = express();
// Register your endpoint
app.post("/files", async (req, res) => {
const controller = filesrocket.controller("cloudinary");
const files = await controller?.create(req, {
extnames: [".jpg", ".png", ".jpeg"]
});
res.status(200).json(files);
});
app.listen(3030, () => {
console.log("App execute in port:3030");
});
With this simple example you can upload files to cloudinary. But remember that this is only the beginning, there is still more to discover, if you are interested I recommend you click here to visit the official documentation.
Top comments (0)