Affects: \
when i upload a file, it throw an exception
java.io.UncheckedIOException: Could not create temp file in /tmp/spring-multipart
at org.springframework.http.codec.multipart.PartGenerator$CreateFileState.createFileState(PartGenerator.java:588)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ com.nxin.passport.application.support.filter.FormDataParserFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ com.nxin.passport.application.support.filter.UrlRewriteFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "/user/uploadPhoto" [ExceptionHandlingWebHandler]
Stack trace:
at org.springframework.http.codec.multipart.PartGenerator$CreateFileState.createFileState(PartGenerator.java:588)
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1789)
at reactor.core.publisher.MonoCacheTime.subscribeOrReturn(MonoCacheTime.java:142)
at reactor.core.publisher.Mono.subscribe(Mono.java:4031)
at reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber.run(MonoSubscribeOn.java:126)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.nio.file.NoSuchFileException: /tmp/spring-multipart/8497015949572241043.multipart
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:215)
at java.base/java.nio.file.Files.newByteChannel(Files.java:370)
at java.base/java.nio.file.Files.createFile(Files.java:647)
at java.base/java.nio.file.TempFileHelper.create(TempFileHelper.java:137)
at java.base/java.nio.file.TempFileHelper.createTempFile(TempFileHelper.java:160)
at java.base/java.nio.file.Files.createTempFile(Files.java:867)
at org.springframework.http.codec.multipart.PartGenerator$CreateFileState.createFileState(PartGenerator.java:580)
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1789)
at reactor.core.publisher.MonoCacheTime.subscribeOrReturn(MonoCacheTime.java:142)
at reactor.core.publisher.Mono.subscribe(Mono.java:4031)
at reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber.run(MonoSubscribeOn.java:126)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
i found DefaultPartHttpMessageReader has a fileStorageDirectory property control the upload temp directory, it init as system temp dir, in linux, it is /tmp/spring-multipart, but os may sometimes remove the files in /tmp, when the spring-multipart is remove, then the upload action will fail, because the directory only init once at startup,
i have found the way to customize the path,
but it did not invoke in any place
please provide some way to config the path, so i can set a other place to store the tepm data to avoid the issure, the spring mvc config way is below
can you provide a similarity one in webflux?
Comment From: poutsma
The field changed by setFileStorageDirectory
is definitely used, even though the setter is not called anywhere. So could you please try again and see if it works for you?
You are correct that some operating systems are quite aggressive when deleting files in the temporary directory. So I did make some changes to make sure that we re-create the file storage directory if it ends up was deleted by the operating system.