Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extended completed file #380

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

feat: extended completed file #380

wants to merge 4 commits into from

Conversation

kukhariev
Copy link
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.

None yet

1 participant