Skip to content

feat: extended completed file#380

Draft
kukhariev wants to merge 4 commits intomasterfrom
extended-file
Draft

feat: extended completed file#380
kukhariev wants to merge 4 commits intomasterfrom
extended-file

Conversation

@kukhariev
Copy link
Copy Markdown
Owner

@kukhariev kukhariev commented Aug 30, 2021

ex:

import * as express from 'express';
import { DiskFile, uploadx } from '@uploadx/core';
import { join } from 'path';

const app = express();

const onComplete: express.RequestHandler = async (req, res, next) => {
  const file = req.body as DiskFile;
  await file.lock(() => ({ statusCode: 202 }));
  const sha1 = await file.hash('sha1');
  await file.move(join('upload', file.originalName));
  await file.lock(() => ({ body: { ...file, sha1 }, statusCode: 200 }));
  if (res.headersSent) return;
  return res.json({ ...file, sha1 });
};

app.all(
  '/files',
  uploadx.upload({
    directory: 'upload',
    expiration: { maxAge: '12h', purgeInterval: '1h' }
  }),
  onComplete
);

app.listen(3002, () => {
  console.log('listening on port:', 3002);
});

@kukhariev kukhariev force-pushed the extended-file branch 2 times, most recently from 56dcdf2 to 67cee68 Compare August 31, 2021 21:32
@kukhariev kukhariev force-pushed the extended-file branch 4 times, most recently from 4c9848d to 7023397 Compare September 3, 2021 11:49
@kukhariev kukhariev mentioned this pull request Sep 3, 2021
@kukhariev kukhariev force-pushed the extended-file branch 2 times, most recently from b3b3a2b to f4356d9 Compare September 3, 2021 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant