File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
master/src/main/java/com/lampo/device_lab/master/service Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .lampo .device_lab .master .service ;
2
2
3
3
import java .io .File ;
4
+ import java .io .FileOutputStream ;
4
5
import java .io .IOException ;
6
+ import java .io .InputStream ;
7
+ import java .io .OutputStream ;
5
8
import java .nio .file .Files ;
6
9
import java .util .ArrayList ;
7
10
import java .util .Arrays ;
16
19
import org .springframework .beans .factory .annotation .Autowired ;
17
20
import org .springframework .context .ApplicationContext ;
18
21
import org .springframework .stereotype .Service ;
22
+ import org .springframework .util .FileCopyUtils ;
19
23
20
24
import com .lampo .device_lab .master .model .Photo ;
21
25
import com .lampo .device_lab .master .repos .IPhoneImageRepository ;
@@ -86,7 +90,17 @@ public class PhoneImageService {
86
90
@ SneakyThrows
87
91
private void uploadDefaultImages () {
88
92
Arrays .stream (context .getResources ("classpath:static/images/phones/*.png" ))
89
- .forEach (e -> phoneImages .add (e .getFilename ().replace (".png" , "" )));
93
+ .forEach (e -> {
94
+ File file = new File (e .getFilename ());
95
+ try (InputStream stream = e .getInputStream (); OutputStream out = new FileOutputStream (file )) {
96
+ FileCopyUtils .copy (stream , out );
97
+ addPhoto (file );
98
+ file .delete ();
99
+ } catch (Exception ex ) {
100
+ ex .printStackTrace ();
101
+ }
102
+ phoneImages .add (e .getFilename ().replace (".png" , "" ));
103
+ });
90
104
91
105
}
92
106
You can’t perform that action at this time.
0 commit comments