Skip to content

Commit d00186e

Browse files
authored
Merge pull request #159 from clowder-framework/bugfix/download-by-url
When adding a file to a dataset by URL, prioritize the URL `content-type` header
2 parents 7a0c181 + 9b29201 commit d00186e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## Unreleased
8+
9+
### Fixed
10+
- When adding a file to a dataset by URL, prioritize the URL `content-type` header over the file content type established
11+
by looking at the file name extension.
12+
713
## 1.14.0 - 2021-01-07
814

915
### Added

app/util/FileUtils.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,18 @@ object FileUtils {
661661
case Some((loader_id, loader, length)) => {
662662
files.get(file.id) match {
663663
case Some(f) => {
664-
val fixedfile = f.copy(contentType=conn.getContentType, loader=loader, loader_id=loader_id, length=length)
665-
files.save(fixedfile)
664+
// if header's content type is application/octet-stream leave content type as the one based on file name,
665+
// otherwise replace with value from header.
666+
val fixedFile = if (conn.getContentType == play.api.http.ContentTypes.BINARY) {
667+
f.copy(loader = loader, loader_id = loader_id, length = length)
668+
} else {
669+
f.copy(contentType = conn.getContentType, loader = loader, loader_id = loader_id, length = length)
670+
}
671+
files.save(fixedFile)
666672
appConfig.incrementCount('files, 1)
667673
appConfig.incrementCount('bytes, f.length)
668674
Logger.debug("Uploading Completed")
669-
Some(fixedfile)
675+
Some(fixedFile)
670676
}
671677
case None => {
672678
Logger.error(s"File $loader_id was not found anymore")

0 commit comments

Comments
 (0)