This is an automated email from the ASF dual-hosted git repository.

mdedetrich pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-pekko-http.git


The following commit(s) were added to refs/heads/main by this push:
     new 23504ab0e Use java NIO to create temp file
23504ab0e is described below

commit 23504ab0e063ffa46b4931dd5d5581e58c565146
Author: Matthew de Detrich <[email protected]>
AuthorDate: Sat Jun 3 23:59:22 2023 +0200

    Use java NIO to create temp file
---
 .../http/scaladsl/server/directives/FileUploadDirectives.scala | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileUploadDirectives.scala
 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileUploadDirectives.scala
index bb9eef0e3..865a2027f 100644
--- 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileUploadDirectives.scala
+++ 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileUploadDirectives.scala
@@ -14,6 +14,7 @@
 package org.apache.pekko.http.scaladsl.server.directives
 
 import java.io.File
+import java.nio.file.Files
 
 import org.apache.pekko
 import pekko.Done
@@ -175,9 +176,12 @@ trait FileUploadDirectives {
       implicit val ec = ctx.executionContext
 
       def tempDest(fileInfo: FileInfo): File = {
-        val dest = File.createTempFile("pekko-http-upload", ".tmp")
-        dest.deleteOnExit()
-        dest
+        val dest = Files.createTempFile("pekko-http-upload", ".tmp")
+        Runtime.getRuntime.addShutdownHook(new Thread() {
+          override def run(): Unit =
+            Files.delete(dest)
+        })
+        dest.toFile
       }
 
       storeUploadedFiles(fieldName, tempDest).map { files =>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to