'Substream Source(EntitySource) cannot be materialized more than once
I'am trying to implement file upload functionality in my application using Akka HTTP. I am using Akka version 2.5.32 and Scala version 2.11.12. I write a simple code with directive storeUploadedFile, like in documentation (https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/file-upload-directives/storeUploadedFile.html):
def uploadFile: Route = (post & path("uploadFile")) {
storeUploadedFile("uploadFile", getDestination) {
(info, file) => complete(JsObject("path" -> JsString(file.getAbsolutePath)))
}
}
private def getDestination(info: FileInfo): File = File.createTempFile(tmpDir, info.fileName)
But when i try to send a request to my application:
curl -F "[email protected]" -X POST localhost:8080/uploadFile
I'll get internal server error and exception:
ERROR [ActorSystemImpl] - Error during processing of request: 'Substream Source(EntitySource) cannot be materialized more than once'. Completing with 500 Internal Server Error response. To change default exception handling behavior, provide a custom ExceptionHandler.
java.lang.IllegalStateException: Substream Source(EntitySource) cannot be materialized more than once
What should i do to upload file without this exception?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
