1
1
package app .controllers
2
2
3
+ import scala .concurrent .ExecutionContext .Implicits .global
3
4
import akka .stream .scaladsl .StreamConverters
4
5
import java .io .InputStream
5
6
import java .nio .charset .StandardCharsets
@@ -32,8 +33,6 @@ final class Application @Inject() (implicit
32
33
33
34
def getAttachment (contentHash : String , typeEncoded : String , filename : String ) = AuthenticatedAction {
34
35
implicit user => implicit request =>
35
- val contentType = typeEncoded.replace('>' , '/' )
36
-
37
36
val folder = playConfiguration.get[String ](" app.accounting.attachmentsFolder" )
38
37
val folderPath = Paths .get(folder)
39
38
@@ -44,17 +43,7 @@ final class Application @Inject() (implicit
44
43
} else if (Files .isDirectory(assetPath)) {
45
44
NotFound (s " Could not find $assetPath" )
46
45
} else {
47
- val connection = assetPath.toFile.toURI.toURL.openConnection()
48
- val stream = connection.getInputStream
49
- val source = StreamConverters .fromInputStream(() => stream)
50
- RangeResult
51
- .ofSource(
52
- entityLength = stream.available(), // TODO: This may not be entirely accurate
53
- source = source,
54
- rangeHeader = request.headers.get(RANGE ),
55
- fileName = Some (filename),
56
- contentType = Some (contentType),
57
- )
46
+ Ok .sendPath(assetPath, inline = true , fileName = _ => Some (filename))
58
47
}
59
48
}
60
49
}
0 commit comments