Permalink
Browse files

Fix bug ZK-1257

- Filedownload.save(media, filename) does not save the media as the specified filename
  • Loading branch information...
1 parent 80c4d16 commit 7bb73e6f5722a86909d5aa3fa70b5ac7507fcb00 @leeyt leeyt committed Nov 13, 2012
View
@@ -57,6 +57,7 @@ ZK 6.5.1
ZK-1295: Disabled buttons cannot regain focus by re-enabling and then setting focus
ZK-1458: Right click on iPad does not work if there are both double click event handler and right click event handler
ZK-1373: Doublebox should not allow the typing of non-numeric characteres achieved by alt-combinations such as @,# and ��
+ ZK-1257: Filedownload.save(media, filename) does not save the media as the specified filename
* Upgrade Notes
+ Decouple Flashchart component from zul.jar to flashchart.jar, due to Flashchart contains a potential
@@ -0,0 +1,57 @@
+<zk>
+ <zscript><![CDATA[
+ import java.io.IOException;
+ import org.zkoss.util.media.Media;
+ import org.zkoss.zhtml.Filedownload;
+ import org.zkoss.zk.ui.Component;
+ import org.zkoss.zk.ui.event.Event;
+ import org.zkoss.zk.ui.event.Events;
+ import org.zkoss.zk.ui.event.EventListener;
+ import org.zkoss.zk.ui.event.UploadEvent;
+ import org.zkoss.zk.ui.util.GenericForwardComposer;
+ import org.zkoss.zul.Button;
+
+ public class TestController extends GenericForwardComposer {
+ private Media media;
+
+ protected Button uploadBtn;
+
+ public void doAfterCompose(Component comp) throws Exception {
+ super.doAfterCompose(comp);
+
+ uploadBtn.addEventListener(Events.ON_UPLOAD, new EventListener() {
+ public void onEvent(Event evt) throws InterruptedException, IOException {
+ uploadHandler(((UploadEvent) evt).getMedia());
+ }
+ });
+ }
+
+ private void uploadHandler(Media media) throws InterruptedException, IOException {
+ this.media = media;
+ }
+
+ public void onClick$download() {
+ Filedownload.save(media, "B65-ZK-1257.png");
+ }
+ }]]>
+ </zscript>
+
+ <html>
+ Test instructions:
+ <ol>
+ <li>Click on "Upload Image" button</li>
+ <li>Upload an image</li>
+ <li>Click on "Download" button to download the uploaded file</li>
+ </ol>
+
+ Expected results:
+ <ul>
+ <li>The downloaded image should be named 'B65-ZK-1257.png'.</li>
+ </ul>
+ </html>
+
+ <window width="100%" apply="TestController">
+ <button id="uploadBtn" label="Upload Image" upload="true,maxsize=300" />
+ <button id="download" label="Download" />
+ </window>
+</zk>
@@ -1448,6 +1448,7 @@ B65-ZK-1324.zul=B,M,Button,Bandbox,FF,Opera
B65-ZK-1295.zul=B,M,Button,focus
B65-ZK-1458.zul=A,M,onDoubleClick,onRightClick,iPad,Android
B65-ZK-1373.zul=B,M,Doublebox,doKeyPress
+B65-ZK-1257.zul=B,M,Filedownload,save
##
# Features - 3.0.x version
@@ -19,6 +19,7 @@
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.IOException;
+import java.net.URLDecoder;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
@@ -424,7 +425,12 @@ void write(HttpServletRequest request, HttpServletResponse response,
if (download) {
String value = "attachment";
- final String flnm = media.getName();
+
+ // Bug ZK-1257: Filedownload.save(media, filename) does not save the media as the specified filename
+ StringBuffer temp = request.getRequestURL();
+ final String saveAs = URLDecoder.decode(temp.substring(temp.lastIndexOf("/")+1), "UTF-8");
+
+ final String flnm = ("".equals(saveAs)) ? media.getName() : saveAs;
if (flnm != null && flnm.length() > 0)
value += ";filename=" + encodeFilename(flnm);
response.setHeader("Content-Disposition", value);

0 comments on commit 7bb73e6

Please sign in to comment.