I have form to upload file on win server. So next I want to download that file.
How can I donwload that file?
Use a StreamResource and FileDownloader. Wiki article written for 7.0.0
https://vaadin.com/wiki/-/wiki/Main/Letting+the+user+download+a+file
About resources in book of Vaadin
https://vaadin.com/book/-/page/application.resources.html#application.resources.stream
Also I have to mention that the popular Viritin add-on has a DownloadButton, that does some of the work for you.
FileDownloader cannot be resolved to a type…
What should I do…?
It’s com.vaadin.server.FileDownloader available in vaadin-server jar. There since 7.0.0. Are you using Vaadin 6 or 7?
There is not com.vaadin.server package, and I’m using 6.8.4v
Hi
Works fine for 6.8.16.
Wrapper class:
[code]
public class MyStreamResource extends StreamResource {
private static final long serialVersionUID = 1;
private DownloadStream downloadStream;
public MyStreamResource(StreamSource streamSource, String filename, Application application) {
super(streamSource, filename, application);
}
@Override
public DownloadStream getStream() {
final StreamSource streamSource = getStreamSource();
if (streamSource == null) {
return null;
}
if (downloadStream == null) {
downloadStream = new DownloadStream(streamSource.getStream(), getMIMEType(), getFilename());
downloadStream.setBufferSize(getBufferSize());
downloadStream.setCacheTime(getCacheTime());
}
return downloadStream;
}
}
[/code]Use:
StreamResource resource = new MyStreamResource(new StreamResource.StreamSource() {
private static final long serialVersionUID = 1L;
@Override
public InputStream getStream() {
InputStream fis = null;
try {
fis = <You input stream>
} catch (FileNotFoundException ex) {
log.error("Error getting file", ex);
}
return fis;
}
}, "myfile", getApplication());
resource.setMIMEType("application/octet-stream");
resource.setCacheTime(0);
resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + "myfile" + "\"");
resource.getStream().setParameter("Content-Transfer-Encoding", "binary");
getMainWindow().open(resource, "_self");
Thanks it’s working
Why are you using vaadin 6? It’s only a matter of curiosity
I suspect that it is necessary to maintain the old project or move to the latest version is too expensive in time and money
It was started already, I’m just fixing some sh*t overhere, who left my cowerker, now ex-coworker
Btw I don’t know how to upgrade to lates version, and I’m not sure if it will works again if I upgrade it.
I’m scared of getting lot of errors