diff --git a/src/main/java/edu/harvard/iq/dataverse/dataaccess/S3AccessIO.java b/src/main/java/edu/harvard/iq/dataverse/dataaccess/S3AccessIO.java index ac4af2e01dd..f17708289fa 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataaccess/S3AccessIO.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataaccess/S3AccessIO.java @@ -39,6 +39,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import java.net.URLEncoder; import java.nio.channels.Channel; import java.nio.channels.Channels; import java.nio.channels.WritableByteChannel; @@ -650,7 +651,19 @@ public String generateTemporaryS3Url() throws IOException { generatePresignedUrlRequest.setMethod(HttpMethod.GET); // Default. generatePresignedUrlRequest.setExpiration(expiration); ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides(); - responseHeaders.setContentDisposition("attachment; filename="+this.getDataFile().getDisplayName()); + //responseHeaders.setContentDisposition("attachment; filename="+this.getDataFile().getDisplayName()); + // Encode the file name explicitly specifying the encoding as UTF-8: + // (otherwise S3 may not like non-ASCII characters!) + // Most browsers are happy with just "filename="+URLEncoder.encode(this.getDataFile().getDisplayName(), "UTF-8") + // in the header. But Firefox appears to require that "UTF8" is + // specified explicitly, as below: + responseHeaders.setContentDisposition("attachment; filename*=UTF-8''"+URLEncoder.encode(this.getDataFile().getDisplayName(), "UTF-8")); + // - without it, download will work, but Firefox will leave the special + // characters in the file name encoded. For example, the file name + // will look like "1976%E2%80%932016.txt" instead of "1976–2016.txt", + // where the dash is the "long dash", represented by a 3-byte UTF8 + // character "\xE2\x80\x93" + responseHeaders.setContentType(this.getDataFile().getContentType()); generatePresignedUrlRequest.setResponseHeaders(responseHeaders);