0.0.5 • Published 1 year ago

tcos-multer-storage v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

TCOS-Multer-Storage

Introduction

A Customer Multer Storage that store the upload file to the TecentCloud Cloud Object Storage.

Usage

Need the TencentCloud permanent key

Get the SecretId and SecretKey on the Manage API Key page in the CAM console.

import express from "express";
import cors from "cors";
import multer from 'multer';
import tcosMulterStorageEngine from 'tcos-multer-storage';

const PORT = process.env.PORT;
const HOST = process.env.HOST;

// SecretId and SecretKey also could be seted at process.env as COS_SECRET_ID and COS_SECRET_KEY
const tcStorage = tcosMulterStorageEngine({
  bucket: process.env.COS_BUCKET,
  region: process.env.COS_REGION,
  // SecretId: process.env.COS_SECRET_ID,
  // SecretKey: process.env.COS_SECRET_KEY,
});

const upload = multer({
  storage: tcStorage,
});

const app = express();

// refer file item attr in the sample-upload
// https://www.tencentcloud.com/document/product/436/43871#uploading-object-by-using-simple-upload 
app.post('/file', upload.any(), (req, res) => {
  res.setHeader("Content-Type", "application/json");
  res.write(JSON.stringify({ body: req.body, files: req.files }));
  res.end();
});

app.listen(PORT, HOST, () => {
  console.log(`Running on http://${HOST}:${PORT}`);
});

app.use(cors());
app.use(express.json());

See more on the example and the __test__

Todo

Reference

0.0.5

1 year ago

0.0.4

1 year ago

0.0.31

1 year ago

0.0.2

1 year ago