Bonjour à tous,

Je suis sur une application Spring boot et j'ai une exception sur le path dans un transfert de fichier avec MultipartFile et .transferTo().

Je n'arrive pas à trouver une solution, et ça fait plusieurs heures que j'essaie de trouver, donc si une bonne âme veut bien me donner un coup de main. Merci d'avance

Mon code de PostMapping:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@PostMapping("add")
public String formPost(@Valid VideoEntity videoEntity, BindingResult bindingResult,
@RequestParam("video-bin") MultipartFile videoBin,
@RequestParam("cover-bin") MultipartFile coverBin,
Model model) {

    if (bindingResult.hasErrors()) {
        return formGet(videoEntity, model);
}


    try {
        videoBin.transferTo(
                new File("/Users/treza/IdeaProjects/webflix/src/main/resources/static/files/vid.mkv"));
} catch (IOException i) {
        model.addAttribute("video-error", "Une erreur s'est produite lors du transfert.");
i.printStackTrace();
        return formGet(videoEntity, model);
}

    try {
        coverBin.transferTo(      //Users\treza\IdeaProjects\webflix\src\main\resources\static\files
new File("/Users/treza/IdeaProjects/webflix/src/main/resources/static/files/200 KDX.jpg"));
} catch (IOException i) {
        model.addAttribute("cover-error", "Une erreur s'est produite lors du transfert.");
i.printStackTrace();
        return formGet(videoEntity, model);
}

    videoEntity.setUrlVideo(videoBin.getOriginalFilename());
videoEntity.setCover(coverBin.getOriginalFilename());

videoService.save(videoEntity);
    return "redirect:/admin/videos";
}
et l'erreur qui en découle:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.5)
 
2022-11-12 19:09:34.146  INFO 27448 --- [  restartedMain] fr.formation.webflix.WebflixApplication  : Starting WebflixApplication using Java 17.0.4.1 on DESKTOP-U9Q5883 with PID 27448 (C:\Users\treza\IdeaProjects\webflix-tourcoing\target\classes started by treza in C:\Users\treza\IdeaProjects\webflix-tourcoing)
2022-11-12 19:09:34.148  INFO 27448 --- [  restartedMain] fr.formation.webflix.WebflixApplication  : No active profile set, falling back to 1 default profile: "default"
2022-11-12 19:09:34.197  INFO 27448 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-11-12 19:09:34.198  INFO 27448 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-11-12 19:09:34.909  INFO 27448 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-11-12 19:09:34.964  INFO 27448 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47 ms. Found 3 JPA repository interfaces.
2022-11-12 19:09:35.721  INFO 27448 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2022-11-12 19:09:35.732  INFO 27448 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-11-12 19:09:35.733  INFO 27448 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-11-12 19:09:35.809  INFO 27448 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-11-12 19:09:35.809  INFO 27448 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1611 ms
2022-11-12 19:09:36.023  INFO 27448 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-11-12 19:09:36.087  INFO 27448 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.12.Final
2022-11-12 19:09:36.264  INFO 27448 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-11-12 19:09:36.367  INFO 27448 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-11-12 19:09:36.514  INFO 27448 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-11-12 19:09:36.542  INFO 27448 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2022-11-12 19:09:37.292  INFO 27448 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-11-12 19:09:37.299  INFO 27448 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
UserEntity(id=null, email=samuel.michaux@ik.me, password=samsamsam, confirmPassword=null, birthday=null, gender=MR, firstname=samuel, lastname=Michaux, country=France, dateCreated=java.util.GregorianCalendar[time=1668276577727,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Paris",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=184,lastRule=java.util.SimpleTimeZone[id=Europe/Paris,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2022,MONTH=10,WEEK_OF_YEAR=45,WEEK_OF_MONTH=2,DAY_OF_MONTH=12,DAY_OF_YEAR=316,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=7,HOUR_OF_DAY=19,MINUTE=9,SECOND=37,MILLISECOND=727,ZONE_OFFSET=3600000,DST_OFFSET=0], dateModified=null, dateDeleted=null, profiles=null)
Hibernate: insert into user (birthday, country, date_created, date_deleted, date_modified, email, firstname, gender, lastname, password) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
UserEntity(id=12, email=samuel.michaux@ik.me, password=samsamsam, confirmPassword=null, birthday=null, gender=MR, firstname=samuel, lastname=Michaux, country=France, dateCreated=java.util.GregorianCalendar[time=1668276577727,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Paris",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=184,lastRule=java.util.SimpleTimeZone[id=Europe/Paris,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2022,MONTH=10,WEEK_OF_YEAR=45,WEEK_OF_MONTH=2,DAY_OF_MONTH=12,DAY_OF_YEAR=316,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=7,HOUR_OF_DAY=19,MINUTE=9,SECOND=37,MILLISECOND=727,ZONE_OFFSET=3600000,DST_OFFSET=0], dateModified=null, dateDeleted=null, profiles=null)
Hibernate: select userentity0_.id as id1_3_, userentity0_.birthday as birthday2_3_, userentity0_.country as country3_3_, userentity0_.date_created as date_cre4_3_, userentity0_.date_deleted as date_del5_3_, userentity0_.date_modified as date_mod6_3_, userentity0_.email as email7_3_, userentity0_.firstname as firstnam8_3_, userentity0_.gender as gender9_3_, userentity0_.lastname as lastnam10_3_, userentity0_.password as passwor11_3_ from user userentity0_
Hibernate: delete from user where id=?
2022-11-12 19:09:37.974  WARN 27448 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-11-12 19:09:38.168  INFO 27448 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2022-11-12 19:09:38.445  WARN 27448 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : Unable to start LiveReload server
2022-11-12 19:09:38.492  INFO 27448 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path ''
2022-11-12 19:09:38.508  INFO 27448 --- [  restartedMain] fr.formation.webflix.WebflixApplication  : Started WebflixApplication in 4.709 seconds (JVM running for 5.159)
2022-11-12 19:09:56.470  INFO 27448 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-11-12 19:09:56.471  INFO 27448 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-11-12 19:09:56.471  INFO 27448 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 0 ms
Hibernate: select categoryen0_.id as id1_1_0_, categoryen0_.name as name2_1_0_ from category categoryen0_ where categoryen0_.id=?
java.io.IOException: java.io.FileNotFoundException: C:\Users\treza\AppData\Local\Temp\tomcat.8081.10694778801708593351\work\Tomcat\localhost\ROOT\Users\treza\IdeaProjects\webflix\src\main\resources\static\files\vid.mkv (The system cannot find the path specified)
    at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:122)
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.transferTo(StandardMultipartHttpServletRequest.java:259)
    at fr.formation.webflix.controllers.admin.video.AdminVideoController.formPost(AdminVideoController.java:71)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:779)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.FileNotFoundException: C:\Users\treza\AppData\Local\Temp\tomcat.8081.10694778801708593351\work\Tomcat\localhost\ROOT\Users\treza\IdeaProjects\webflix\src\main\resources\static\files\vid.mkv (The system cannot find the path specified)
    at java.base/java.io.FileOutputStream.open0(Native Method)
    at java.base/java.io.FileOutputStream.open(FileOutputStream.java:293)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:184)
    at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:409)
    at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:120)
    ... 52 more
Hibernate: select categoryen0_.id as id1_1_, categoryen0_.name as name2_1_ from category categoryen0_
Hibernate: select videos0_.category_id as categor11_4_0_, videos0_.id as id1_4_0_, videos0_.id as id1_4_1_, videos0_.category_id as categor11_4_1_, videos0_.cover as cover2_4_1_, videos0_.date_deleted as date_del3_4_1_, videos0_.date_published as date_pub4_4_1_, videos0_.duration as duration5_4_1_, videos0_.name as name6_4_1_, videos0_.origin_country as origin_c7_4_1_, videos0_.product_year as product_8_4_1_, videos0_.synopsis as synopsis9_4_1_, videos0_.url_video as url_vid10_4_1_ from video videos0_ where videos0_.category_id=?
Je n'ai certainement pas mis tout ce qu'il faut pour arriver à trouver ou est le problème, donc n'hésitez pas.