hi all, when uploading a file through a multipart ...
# http4k
j
hi all, when uploading a file through a multipart form, we want to keep the temp file around for async virus scanning. However, in the following piece of code, the file is deleted upon JVM exit:
Copy code
private fun writeToDisk(part: StreamingPart, bytes: ByteArray, length: Int) =
        File.createTempFile(part.fileName ?: UUID.randomUUID().toString()
        + "-", ".tmp", temporaryFileDirectory).apply {
            deleteOnExit()
            FileOutputStream(this).apply {
                write(bytes, 0, length)
                use { part.inputStream.copyTo(it, writeToDiskThreshold) }
            }
        }
with the
deleteOnExit()
call. We want to keep the file around even when the JVM exits (we're running on k8s so pods can always be killed). Would it be a good idea to make this behaviour configurable, i.e. through a flag that is passed from
MultipartFormBody.from
to the
MultipartFormParser
? If so, I'll make a merge request... Happy to hear your thoughts.
the alternative would be to make a copy of the temp file, but that seems a bit wasteful...