Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
Overview
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
Patryk Czarnik
java_weekendowa_20221008
Commits
25611a95
Commit
25611a95
authored
Nov 27, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload zdjęć
parent
e8a306e9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
PhotoUtil.java
PC32-RestSpring/src/main/java/sklep/photo/PhotoUtil.java
+3
-4
ProductController.java
...estSpring/src/main/java/sklep/rest/ProductController.java
+5
-0
No files found.
PC32-RestSpring/src/main/java/sklep/photo/PhotoUtil.java
View file @
25611a95
...
...
@@ -2,11 +2,10 @@ package sklep.photo;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Standard
Copy
Option
;
import
java.nio.file.Standard
Open
Option
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -40,10 +39,10 @@ public class PhotoUtil {
}
}
public
void
writeStream
(
int
productId
,
InputStream
inputStream
)
{
public
void
writeStream
(
int
productId
,
byte
[]
bytes
)
{
try
{
Path
path
=
getPath
(
productId
);
Files
.
copy
(
inputStream
,
path
,
StandardCopyOption
.
REPLACE_EXISTING
);
Files
.
write
(
path
,
bytes
,
StandardOpenOption
.
CREATE
);
}
catch
(
Exception
e
)
{
// wypisujemy błąd, ale metoda kończy się normalnie
e
.
printStackTrace
();
...
...
PC32-RestSpring/src/main/java/sklep/rest/ProductController.java
View file @
25611a95
package
sklep
.
rest
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Optional
;
...
...
@@ -151,4 +152,8 @@ public class ProductController {
return
photoUtil
.
readBytes
(
productId
);
}
@PutMapping
(
path
=
"/{id}/photo"
,
consumes
=
"image/jpeg"
)
public
void
uploadPhoto
(
@PathVariable
(
"id"
)
int
productId
,
@RequestBody
byte
[]
bytes
)
{
photoUtil
.
writeStream
(
productId
,
bytes
);
}
}
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