Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
d5e6d62e
Commit
d5e6d62e
authored
Oct 10, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://git.janhrabal.com:4022/janh683/jh-boot
parents
bafb0c49
380e1eab
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
AttachmentApiController.java
...a/com/jh/boot/attachment/api/AttachmentApiController.java
+25
-0
No files found.
src/main/java/com/jh/boot/attachment/api/AttachmentApiController.java
View file @
d5e6d62e
package
com
.
jh
.
boot
.
attachment
.
api
;
package
com
.
jh
.
boot
.
attachment
.
api
;
import
java.io.InputStream
;
import
java.util.List
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.core.io.InputStreamResource
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -11,6 +17,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -11,6 +17,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
com.jh.boot.attachment.Attachment
;
import
com.jh.boot.attachment.Attachment
;
import
com.jh.boot.attachment.AttachmentService
;
import
com.jh.boot.attachment.AttachmentService
;
import
com.jh.boot.web.error.NotFoundException
;
@Controller
@Controller
@ConditionalOnBean
(
AttachmentService
.
class
)
@ConditionalOnBean
(
AttachmentService
.
class
)
...
@@ -26,5 +33,23 @@ public class AttachmentApiController {
...
@@ -26,5 +33,23 @@ public class AttachmentApiController {
}
}
@GetMapping
(
"/attachments/{attachmentId}"
)
public
ResponseEntity
<
InputStreamResource
>
fetch
(
@PathVariable
(
"unitId"
)
Long
unitId
,
@PathVariable
(
"objectType"
)
String
objectType
,
@PathVariable
(
"objectId"
)
Long
objectId
,
@PathVariable
(
"attachmentId"
)
Long
attachmentId
)
{
Attachment
a
=
service
.
fetchAttachment
(
attachmentId
);
if
(
a
==
null
)
{
throw
new
NotFoundException
();
}
InputStream
is
=
service
.
fetchAttachmentBody
(
a
);
if
(
is
==
null
)
{
throw
new
NotFoundException
();
}
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM
);
headers
.
set
(
"Content-Disposition"
,
"attachment; filename=\""
+
a
.
getName
()
+
"\""
);
return
new
ResponseEntity
<>(
content
,
headers
,
HttpStatus
.
OK
);
}
}
}
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