Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with Chrome downloading files with commas in the filename #900

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/org/ohmage/request/audio/AudioReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void respond(

httpResponse.setHeader(
"Content-Disposition",
"attachment; filename=" + audio.getFileName());
"attachment; filename=\"" + audio.getFileName() + "\"");
httpResponse.setHeader(
"Content-Length",
new Long(audio.getFileSize()).toString());
Expand Down Expand Up @@ -225,4 +225,4 @@ public void respond(
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/org/ohmage/request/campaign/CampaignReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ else if(OutputFormat.XML.equals(outputFormat)) {
httpResponse
.setHeader(
"Content-Disposition",
"attachment; filename=" + campaign.getName() + ".xml");
"attachment; filename=\"" + campaign.getName() + ".xml\"");

try {
responseText = campaign.getXml();
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohmage/request/clazz/ClassRosterReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResp
// Set the type and force the browser to download it as the
// last step before beginning to stream the response.
httpResponse.setContentType("ohmage/roster");
httpResponse.setHeader("Content-Disposition", "attachment; filename=roster.csv");
httpResponse.setHeader("Content-Disposition", "attachment; filename=\"roster.csv\"");

// If available, set the token.
if(getUser() != null) {
Expand Down
4 changes: 2 additions & 2 deletions src/org/ohmage/request/image/ImageBatchZipReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void respond(
// the header to indicate that this will be an attachment.
httpResponse.setHeader(
"Content-Disposition",
"attachment; filename=images.zip");
"attachment; filename=\"images.zip\"");

// Create the zip stream to the outside world.
ZipOutputStream zipStream = null;
Expand Down Expand Up @@ -341,4 +341,4 @@ else if(response instanceof RepeatableSetResponse) {

return result;
}
}
}
4 changes: 2 additions & 2 deletions src/org/ohmage/request/image/ImageZipReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void respond(
// the header to indicate that this will be an attachment.
httpResponse.setHeader(
"Content-Disposition",
"attachment; filename=images.zip");
"attachment; filename=\"images.zip\"");

// Create the zip stream to the outside world.
ZipOutputStream zipStream = null;
Expand Down Expand Up @@ -256,4 +256,4 @@ else if(response instanceof RepeatableSetResponse) {

return result;
}
}
}
4 changes: 2 additions & 2 deletions src/org/ohmage/request/media/MediaReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void respond(
// only set content-disposition if media is not video/image/audio
if (contentType.startsWith("application") || contentType.startsWith("text"))
httpResponse.setHeader("Content-Disposition",
"attachment; filename=" + media.getFileName());
"attachment; filename=\"" + media.getFileName() + "\"");

httpResponse.setHeader("Content-Length",
new Long(media.getFileSize()).toString());
Expand Down Expand Up @@ -265,4 +265,4 @@ public void respond(
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/org/ohmage/request/mobility/MobilityReadCsvRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void respond(
// Set the type and force the browser to download it as the
// last step before beginning to stream the response.
httpResponse.setContentType("text/csv");
httpResponse.setHeader("Content-Disposition", "attachment; filename=Mobility.csv");
httpResponse.setHeader("Content-Disposition", "attachment; filename=\"Mobility.csv\"");

// If available, set the token.
if(getUser() != null) {
Expand Down Expand Up @@ -368,4 +368,4 @@ public void respond(
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
}
8 changes: 4 additions & 4 deletions src/org/ohmage/request/survey/SurveyResponseReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1248,10 +1248,10 @@ else if(OutputFormat.CSV.equals(outputFormat)) {
// Mark it as an attachment.
httpResponse.setContentType("text/csv");
httpResponse.setHeader(
"Content-Disposition",
"attachment; filename=" +
getCampaign().getName() +
".csv");
"Content-Disposition",
"attachment; filename=\"" +
getCampaign().getName() +
".csv\"");

StringBuilder resultBuilder = new StringBuilder();

Expand Down
4 changes: 2 additions & 2 deletions src/org/ohmage/request/video/VideoReadRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void respond(

httpResponse.setHeader(
"Content-Disposition",
"attachment; filename=" + video.getFileName());
"attachment; filename=\"" + video.getFileName() + "\"");
httpResponse.setHeader(
"Content-Length",
new Long(video.getFileSize()).toString());
Expand Down Expand Up @@ -213,4 +213,4 @@ public void respond(
}
}
}
}
}