Created
August 15, 2022 15:07
-
-
Save melnikovdv/13f497ba85882a35b8d321cfb3e39e26 to your computer and use it in GitHub Desktop.
Upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller("/") | |
@ExecuteOn(TaskExecutors.IO) | |
class UploadController { | |
companion object { | |
private val LOG = LoggerFactory.getLogger(UploadController::class.java) | |
private val executor = Executors.newSingleThreadExecutor { | |
Thread(it).apply { | |
name = "processing-thread" | |
} | |
} | |
private val scheduler = Schedulers.fromExecutorService(executor) | |
} | |
@Consumes(MediaType.MULTIPART_FORM_DATA) | |
@Post("/upload") fun post( | |
@Part("file") fileUpload: StreamingFileUpload, | |
httpRequest: HttpRequest<*> | |
): Mono<HttpResponse<String>> { | |
LOG.info("Entered endpoint") | |
return Mono.fromDirect(fileUpload.transferTo(File("x.tmp"))) | |
.handle { success, sink -> | |
if (!success || !fileUpload.isComplete) { | |
LOG.info("Not success") | |
sink.error(RuntimeException("Failed to transfer file")) | |
} else { | |
LOG.info("Success") | |
sink.next(HttpResponse.ok("File uploaded! :)")) | |
sink.complete() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment