An Interest In:
Web News this Week
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
April 18, 2022 07:33 pm GMT
Original Link: https://dev.to/ivanzm123/upload-files-to-cloudinary-with-nodejs-in-1-minute-3ll
Upload Files to Cloudinary with Node.js in 1 minute
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-appcd my-filesrocket-appcode .
Initialize project
npm i typescript ts-node -gnpm init -ytsc --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-cloudinarynpm 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 Filesrocketconst 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 endpointapp.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.
Follow me
Original Link: https://dev.to/ivanzm123/upload-files-to-cloudinary-with-nodejs-in-1-minute-3ll
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To