Skip to content
Snippets Groups Projects
Unverified Commit 433a2532 authored by Ivan Alglave's avatar Ivan Alglave Committed by GitHub
Browse files

Merge pull request #15 from ivanalglave/upload-fix

Upload fix
parents c930f7ea e04359f4
No related branches found
No related tags found
No related merge requests found
...@@ -60,13 +60,19 @@ export class InternshipsController { ...@@ -60,13 +60,19 @@ export class InternshipsController {
// uploads even if invalid state... // uploads even if invalid state...
@Put(':studentId/:state') @Put(':studentId/:state')
@UseInterceptors( @UseInterceptors(
FileInterceptor('pdf', { FileInterceptor('file', {
storage: diskStorage({ storage: diskStorage({
destination: './files', destination: './files',
filename: (_req, _file, cb) => { filename: (_req, _file, cb) => {
return cb(null, `${v4()}.pdf`); return cb(null, `${v4()}.pdf`);
}, },
}), }),
fileFilter: (req, file, cb) => {
if (!file.originalname.match(/\.pdf$/)) {
return cb(new Error('Only PDF files are allowed!'), false);
}
cb(null, true);
},
}), }),
) )
updateState( updateState(
......
...@@ -19,7 +19,7 @@ export class ResourcesController { ...@@ -19,7 +19,7 @@ export class ResourcesController {
@Param('filename') filename, @Param('filename') filename,
@Res({ passthrough: true }) res: Response, @Res({ passthrough: true }) res: Response,
): StreamableFile { ): StreamableFile {
const filepath = `files\\${filename}`; const filepath = `files/${filename}`;
if (!existsSync(filepath)) throw NOT_FOUND; if (!existsSync(filepath)) throw NOT_FOUND;
const file = createReadStream(filepath); const file = createReadStream(filepath);
res.set({ res.set({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment