@blocklet/uploader-server v0.1.101
@blocklet/uploader-server
@blocklet/uploader-server is a package that integrates the uppy service to provide universal upload capability for blocklets. For more information about uppy, refer to the official documentation.
Package Structure
The package is composed of both frontend and backend components. The backend code can be found in the middlewares folder.
Development
Install In Blocklet
# You can use npm / yarn
pnpm add @blocklet/uploader-serverInstall Dependencies
To install the required dependencies, run the following command:
pnpm iBuild Packages
To build the packages, execute the following command:
pnpm buildBuild, Watch, and Run Development Server
For building, watching changes, and running the development server, use the following command:
pnpm run devBackend Example
import { initLocalStorageServer, initCompanion } from '@blocklet/uploader-server';
// init uploader server
const localStorageServer = initLocalStorageServer({
path: env.uploadDir,
express,
onUploadFinish: async (req, res, uploadMetadata) => {
const {
id: filename,
size,
metadata: { filename: originalname, filetype: mimetype },
} = uploadMetadata;
const obj = new URL(env.appUrl);
obj.protocol = req.get('x-forwarded-proto') || req.protocol;
obj.pathname = joinUrl(req.headers['x-path-prefix'] || '/', '/uploads', filename);
const doc = await Upload.insert({
mimetype,
originalname,
filename,
size,
remark: req.body.remark || '',
tags: (req.body.tags || '')
.split(',')
.map((x) => x.trim())
.filter(Boolean),
folderId: req.componentDid,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
createdBy: req.user.did,
updatedBy: req.user.did,
});
const resData = { url: obj.href, ...doc };
return resData;
},
});
router.use('/uploads', user, auth, ensureComponentDid, localStorageServer.handle);
// if you need to load file from remote
// companion
const companion = initCompanion({
path: env.uploadDir,
express,
providerOptions: env.providerOptions,
uploadUrls: [env.appUrl],
});
router.use('/companion', user, auth, ensureComponentDid, companion.handle);License
This package is licensed under the MIT license.
7 months ago
1 year ago
7 months ago
1 year ago
6 months ago
12 months ago
6 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
1 year ago
9 months ago
9 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
11 months ago
6 months ago
6 months ago
1 year ago
1 year ago