Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
I
Inovasi Daerah Master
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ghitha Dinan
Inovasi Daerah Master
Commits
d7ad7ed6
Commit
d7ad7ed6
authored
Sep 27, 2021
by
Ghitha Dinan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add file contoller
parent
76247feb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
21 deletions
+55
-21
FileConstant.kt
...angkuriang/inovasi/daerah/master/constant/FileConstant.kt
+0
-5
FileController.kt
...uriang/inovasi/daerah/master/controller/FileController.kt
+53
-0
Helpers.kt
...d/co/sangkuriang/inovasi/daerah/master/utility/Helpers.kt
+2
-16
No files found.
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/constant/FileConstant.kt
View file @
d7ad7ed6
...
@@ -6,10 +6,5 @@ const val ROOT_DIR = "C:\\Users\\ghith\\Desktop\\inovasi_daerah_master\\"
...
@@ -6,10 +6,5 @@ const val ROOT_DIR = "C:\\Users\\ghith\\Desktop\\inovasi_daerah_master\\"
//const val ROOT_DIR = "/home/inovasi_daerah_master/data/"
//const val ROOT_DIR = "/home/inovasi_daerah_master/data/"
val
UPLOAD_DIR
=
"${ROOT_DIR}uploads${File.separator}"
val
UPLOAD_DIR
=
"${ROOT_DIR}uploads${File.separator}"
val
UPLOAD_USER_DIR
=
"${UPLOAD_DIR}users"
val
UPLOAD_APPLICATION_DIR
=
"${UPLOAD_DIR}application"
val
UPLOAD_BANNER_APPLICATION_DIR
=
"$UPLOAD_APPLICATION_DIR${File.separator}video"
val
UPLOAD_IMAGE_APPLICATION_QR_DIR
=
"$UPLOAD_APPLICATION_DIR${File.separator}qr"
val
UPLOAD_IMAGE_APPLICATION_DETAIL_DIR
=
"$UPLOAD_APPLICATION_DIR${File.separator}detail"
val
UPLOAD_ICON_APPLICATION_CATEGORY_DIR
=
"${UPLOAD_DIR}apllication_category/icon"
val
UPLOAD_ICON_APPLICATION_CATEGORY_DIR
=
"${UPLOAD_DIR}apllication_category/icon"
val
UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
=
"${UPLOAD_DIR}apllication_category/image"
val
UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
=
"${UPLOAD_DIR}apllication_category/image"
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/controller/FileController.kt
0 → 100644
View file @
d7ad7ed6
package
id.co.sangkuriang.inovasi.daerah.master.controller
import
id.co.sangkuriang.inovasi.daerah.master.constant.*
import
id.co.sangkuriang.inovasi.daerah.master.exception.NotFoundException
import
org.apache.commons.io.IOUtils
import
org.springframework.http.MediaType
import
org.springframework.stereotype.Controller
import
org.springframework.web.bind.annotation.RequestMapping
import
org.springframework.web.bind.annotation.RequestMethod
import
org.springframework.web.bind.annotation.RequestParam
import
org.springframework.web.bind.annotation.ResponseBody
import
java.io.File
import
java.io.FileInputStream
import
javax.servlet.http.HttpServletResponse
@Controller
@RequestMapping
(
"file"
)
class
FileController
{
@RequestMapping
(
value
=
[
"images"
],
method
=
[
RequestMethod
.
GET
],
produces
=
[
MediaType
.
IMAGE_JPEG_VALUE
,
MediaType
.
IMAGE_PNG_VALUE
]
)
@ResponseBody
fun
images
(
@RequestParam
type
:
String
,
@RequestParam
fileName
:
String
,
response
:
HttpServletResponse
):
ByteArray
?
{
try
{
var
dir
=
""
when
(
type
)
{
"application-category-icon"
->
{
dir
=
UPLOAD_ICON_APPLICATION_CATEGORY_DIR
}
"application-category-image"
->
{
dir
=
UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
}
}
val
file
=
File
(
dir
+
File
.
separator
+
fileName
)
if
(
file
.
exists
())
{
val
fis
=
FileInputStream
(
file
)
return
IOUtils
.
toByteArray
(
fis
)
}
throw
NotFoundException
()
}
catch
(
e
:
Exception
)
{
throw
e
}
}
}
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/utility/Helpers.kt
View file @
d7ad7ed6
package
id.co.sangkuriang.inovasi.daerah.master.utility
package
id.co.sangkuriang.inovasi.daerah.master.utility
import
com.fasterxml.jackson.databind.ObjectMapper
import
com.fasterxml.jackson.databind.ObjectMapper
import
id.co.sangkuriang.inovasi.daerah.master.constant.*
import
id.co.sangkuriang.inovasi.daerah.master.constant.UPLOAD_ICON_APPLICATION_CATEGORY_DIR
import
id.co.sangkuriang.inovasi.daerah.master.constant.UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
import
id.co.sangkuriang.inovasi.daerah.master.pojo.Users
import
id.co.sangkuriang.inovasi.daerah.master.pojo.Users
import
org.apache.commons.io.FileUtils
import
org.apache.commons.io.FileUtils
import
org.springframework.security.core.context.SecurityContextHolder
import
org.springframework.security.core.context.SecurityContextHolder
...
@@ -63,27 +64,12 @@ fun uploadFile(
...
@@ -63,27 +64,12 @@ fun uploadFile(
try
{
try
{
var
dirType
=
""
var
dirType
=
""
when
(
path
)
{
when
(
path
)
{
UPLOAD_USER_DIR
->
{
dirType
=
"users"
}
UPLOAD_APPLICATION_DIR
->
{
dirType
=
"application"
}
UPLOAD_ICON_APPLICATION_CATEGORY_DIR
->
{
UPLOAD_ICON_APPLICATION_CATEGORY_DIR
->
{
dirType
=
"application-category-icon"
dirType
=
"application-category-icon"
}
}
UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
->
{
UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
->
{
dirType
=
"application-category-image"
dirType
=
"application-category-image"
}
}
UPLOAD_BANNER_APPLICATION_DIR
->
{
dirType
=
"application-banner"
}
UPLOAD_IMAGE_APPLICATION_QR_DIR
->
{
dirType
=
"application-qr"
}
UPLOAD_IMAGE_APPLICATION_DETAIL_DIR
->
{
dirType
=
"application-detail"
}
}
}
val
root
:
Path
=
Paths
.
get
(
path
)
val
root
:
Path
=
Paths
.
get
(
path
)
...
...
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