We have a download file link written using Wicket, and despite our best efforts, we cannot get it so the file can be downloaded with spaces... the file name is always encoded such that the spaces are converted to plus '+' signs.
Example: "My File.xls" is getting converted when downloaded to "My+File.xls"
See below for the code that we are using. We have tried playing with several options here, but the problem persists. Hoping someone help us narrow our search on what the problem area is.
Also, the resourceStream.downloadLink.prepareFileName()
returns with "My File.xls" here, with the quotes excluded. We tried wrapping the filename with quotes which did not seem to work.
public DownloadLinkListActionCell(String componentId, IModel<DownloadLink> rowModel) {
super(componentId, rowModel);
downloadLink = rowModel.getObject();
IModel fileModel = new AbstractReadOnlyModel(){
public Object getObject() {
return generateFile();
}
};
Link downloadFileLink = new Link("download") {
@Override
public void onClick() {
File downloadFile = (File) fileModel.getObject();
IResourceStream resourceStream = new FileResourceStream(
new org.apache.wicket.util.file.File(downloadFile));
getRequestCycle().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(resourceStream,downloadLink.prepareFileName())
{
@Override
public void respond(IRequestCycle requestCycle)
{
super.respond(requestCycle);
}
}.setContentDisposition(ContentDisposition.ATTACHMENT)
.setCacheDuration(Duration.NONE)
);
setResponsePage(DownloadLinkPage.class, PageParametersBuilder.uniqueId(downloadLink.getId()));
}
};
}