Skip to content

Commit

Permalink
Merge pull request #8392 from IQSS/8344-file-upload-default-mime
Browse files Browse the repository at this point in the history
8344 file upload: default mime type
  • Loading branch information
kcondon committed Mar 8, 2022
2 parents a629d18 + 8698f78 commit 1487650
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,23 @@ public Response addFileToDataset(@PathParam("id") String idSupplied,
}
} else {
newFilename = contentDispositionHeader.getFileName();
newFileContentType = formDataBodyPart.getMediaType().toString();
// Let's see if the form data part has the mime (content) type specified.
// Note that we don't want to rely on formDataBodyPart.getMediaType() -
// because that defaults to "text/plain" when no "Content-Type:" header is
// present. Instead we'll go through the headers, and see if "Content-Type:"
// is there. If not, we'll default to "application/octet-stream" - the generic
// unknown type. This will prompt the application to run type detection and
// potentially find something more accurate.
//newFileContentType = formDataBodyPart.getMediaType().toString();

for (String header : formDataBodyPart.getHeaders().keySet()) {
if (header.equalsIgnoreCase("Content-Type")) {
newFileContentType = formDataBodyPart.getHeaders().get(header).get(0);
}
}
if (newFileContentType == null) {
newFileContentType = FileUtil.MIME_TYPE_UNDETERMINED_DEFAULT;
}
}


Expand Down

0 comments on commit 1487650

Please sign in to comment.