From 9080bfa91db6fb377348dc94acc4cd171683ea83 Mon Sep 17 00:00:00 2001 From: ParkHyunSoo Date: Tue, 5 Sep 2023 22:59:12 +0900 Subject: [PATCH] =?UTF-8?q?TASK=20#49=20:=20images=20=EB=94=94=EB=A0=89?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EC=97=86=EC=9C=BC=EB=A9=B4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 코드에선 images 디렉토리가 없으면 에러 발생하여 images 디렉토리를 생성하는 것으로 처리했습니다. - images 디렉토리가 없어도 에러를 발생시키지 않고 images 디렉토리를 생성하도록 코드를 수정했습니다. --- Server/app.js | 4 ++-- Server/services/boardSystem.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Server/app.js b/Server/app.js index 8ab704d..1a22298 100644 --- a/Server/app.js +++ b/Server/app.js @@ -8,8 +8,8 @@ const postRouter = require('./routes/board.js'); const likeRouter = require('./routes/like.js'); dotenv.config(); -app.use(express.urlencoded({extended : true})); -app.use(bodyParser.json()); +app.use(express.urlencoded({limit: '100mb', extended : true})); +app.use(bodyParser.json({limit: '100mb'})); app.use('/public', express.static('public')); /* 안드로이드와 HTTP 통신 */ diff --git a/Server/services/boardSystem.js b/Server/services/boardSystem.js index ecc8313..2afdd49 100644 --- a/Server/services/boardSystem.js +++ b/Server/services/boardSystem.js @@ -87,6 +87,14 @@ module.exports = { const base64Image = Buffer.from(postData.image_data, 'base64'); const savePath = path.join(__dirname, '..', 'public', 'images', postData.image_name); + // public/images 디렉토리에 접근 가능한지 판단 (해당 디렉토리가 있는지) + try { + await fs.access(path.join(__dirname, 'public', 'images')) + } catch (error) { + console.log(error.message); + await fs.mkdir(path.join(__dirname, 'public', 'images'), {recursive : true}); // 디렉토리 없으면 생성 + } + // 디코딩한 이미지 저장 await fs.writeFile(savePath, base64Image); console.log('Save Complete : ' + savePath);