Skip to content

Commit

Permalink
Merge pull request #4542 from IQSS/4524-s3-redirects-utf8-filenames
Browse files Browse the repository at this point in the history
4524 s3 redirects utf8 filenames
  • Loading branch information
kcondon authored Mar 28, 2018
2 parents 831ba36 + e5184a1 commit 3845816
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3845816

Please sign in to comment.