Skip to content

Commit

Permalink
Save to server
Browse files Browse the repository at this point in the history
  • Loading branch information
icemedia001 committed Dec 13, 2023
1 parent 5a4f28d commit fdf15c7
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/App/Upload/upload.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Controller, Post, UploadedFile, UseInterceptors, Res } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { Response } from 'express';
import * as fs from 'fs';
import {
Controller,
Post,
UploadedFile,
UseInterceptors,
Res,
} from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express'
import { Response } from 'express'
import * as fs from 'fs'

@Controller('file')
export class UploadController {
Expand All @@ -15,22 +21,22 @@ export class UploadController {
if (file.mimetype !== 'application/json') {
return res.status(400).json({
error: 'Invalid format, must be a JSON file.',
});
})
}

const filePath = `./uploads/${file.originalname}`;
fs.writeFileSync(filePath, file.buffer);
const filePath = `./uploads/${file.originalname}`
fs.writeFileSync(filePath, file.buffer)

return res.json({
message: 'JSON file uploaded successfully',
});
})
} catch (error) {
console.error('Error uploading file:', error);
console.error('Error uploading file:', error)
return res.status(500).json({
error: 'Internal Server Error',
});
})
}
}
}

export default UploadController;
export default UploadController

0 comments on commit fdf15c7

Please sign in to comment.