Hi all,
I have this issue with downloading a temporary file from a StreamResource attached to the application. Whenever I “download” the file, it keeps reloading the application or creates a new application window. When I “save as” the file, it contains the html output of the application, not the actual file content.
StreamSource source = new StreamSource() {
public InputStream getStream() {
byte[] b = null;
String ppp = "<table><tr><td><span>djfdlkfj</span></td></tr></table>";
b = ppp.getBytes();
System.out.println("################### getStream reported");
return new ByteArrayInputStream(b);
}
};
final StreamResource resource = new StreamResource(source, "database.txt", this );
resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + "database.txt" + "\"");
resource.setMIMEType("application/octet-stream");
resource.setCacheTime(0);
Link downloadlink = new Link("Download test file", resource);
mainWindow.addComponent(downloadlink);
I have now discovered that the issue has been influenced by the current HandleURI I had wrote before to process other parameters:
public DownloadStream handleURI(URL context, String relativeUri) {
// Catch the given URI that identifies the resource,
// otherwise let other URI handlers or the Application
// to handle the response.
if ( !relativeUri.startsWith("command") ) {
System.out.println("Returning null since uri parameter is a non-command. RelativeUri: " + relativeUri);
return null;
}
<rest of code>
}
My question is
… what can I change in the HandleURI to allow the StreamResource download to work, without reloading the application? I have no idea what to return if I add this following code in the HandleURI…
public DownloadStream handleURI(URL context, String relativeUri) {
// Catch the given URI that identifies the resource,
// otherwise let other URI handlers or the Application
// to handle the response.
[b]
if ( relativeUri.startsWith("APP") ) {
[/b]
return [b]
?????
[/b];
}
if ( !relativeUri.startsWith("command") ) {
System.out.println("Returning null since uri parameter is a non-command. RelativeUri: " + relativeUri);
return null;
}
<rest of code>
}