Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
8ba8236b
Commit
8ba8236b
authored
Jul 26, 2022
by
Yoon, Daeki
😅
Browse files
upload files가 없을 때 버그 처리
parent
b2d9face
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/controllers/answer.controller.ts
View file @
8ba8236b
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
{
asyncWrap
}
from
"
../helpers
"
;
import
{
asyncWrap
,
isEmpty
}
from
"
../helpers
"
;
import
{
TypedRequest
}
from
"
../types
"
;
import
{
TypedRequest
}
from
"
../types
"
;
import
formidable
from
"
formidable
"
;
import
formidable
from
"
formidable
"
;
import
{
FileInfo
}
from
"
../models
"
;
import
{
FileInfo
}
from
"
../models
"
;
...
@@ -15,11 +15,14 @@ export const createAnswers = asyncWrap(async (reqExp, res) => {
...
@@ -15,11 +15,14 @@ export const createAnswers = asyncWrap(async (reqExp, res) => {
if
(
Array
.
isArray
(
req
.
files
.
uploadFiles
))
{
if
(
Array
.
isArray
(
req
.
files
.
uploadFiles
))
{
files
=
req
.
files
.
uploadFiles
as
formidable
.
File
[];
files
=
req
.
files
.
uploadFiles
as
formidable
.
File
[];
}
else
{
}
else
{
files
.
push
(
req
.
files
.
uploadFiles
);
if
(
!
isEmpty
(
req
.
files
))
{
files
.
push
(
req
.
files
.
uploadFiles
);
}
}
}
let
uploadFile
;
let
uploadFile
;
try
{
try
{
if
(
files
)
{
if
(
files
.
length
>
0
)
{
console
.
log
(
"
files in answer controller:
"
,
files
);
// 1) 파일을 DB에 저장 후 다시 retFile가져와서
// 1) 파일을 DB에 저장 후 다시 retFile가져와서
// *근데 파일이 여러 개일 수 있기 때문에 순회해야 됨
// *근데 파일이 여러 개일 수 있기 때문에 순회해야 됨
const
f
=
files
.
map
(
async
(
file
)
=>
{
const
f
=
files
.
map
(
async
(
file
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment