0

Filedownload.save is not working in chrome

asked 2015-10-09 14:48:04 +0800

hmannam gravatar image hmannam
153 2

Hi,

We are in the process of upgrading our application from zk5 to zk7. In zk7, filedownload.save is not working in chrome, ie etc.

Tried to use Filedownload.saveresumable as mentioned in the article but no luck.

Please advise.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2015-10-11 21:42:06 +0800

Darksu gravatar image Darksu
1991 1 4

Hello hmannam,

First of all for information regarding file download please refer to the following url:

http://books.zkoss.org/wiki/ZKComponentReference/Essential_Components/Filedownload

Furthermore in my environment using zk 7 it works as expected, but in order to help the best way is to post the following:

  1. sample code
  2. zk version
  3. chrome version

Best Regards,

Darksu

link publish delete flag offensive edit

answered 2015-10-12 03:12:03 +0800

kleponboy gravatar image kleponboy flag of Indonesia
54 5
http://stupidprogrammers....

Hi Hmnnam,

I'am also using ZK7 and the FileDownload.save is running just fine. maybe you could post your code snippet and error log.

Warm Regards,

KleponBoy

link publish delete flag offensive edit

answered 2015-10-12 11:52:00 +0800

hmannam gravatar image hmannam
153 2

updated 2015-10-12 12:08:07 +0800

Thanks for your replies and here is what you have requested for,

Zk version: 7.0.3 Chrome version: Version 45.0.2454.101 m (64-bit)

Sample code:

this is the code from controller class, if (feeds != null) { //TEMR-189 //if(feeds.size() != 0){ Span sp = new Span(); final Image img = new Image(); img.setSrc(IconUtil.getIconPath("download-icon.png", null, "temr")); img.setStyle("cursor:pointer; padding-left:180px"); img.setParent(sp); img.setTooltiptext("download previous feedback and student reflection"); previousFeedbackVlayout.appendChild(sp);

                img.addEventListener(Events.ON_CLICK, new EventListener() {

                    @Override
                    public void onEvent(final Event event) throws Exception {
                        String studentName = service.getUser(((Person) (studentListbox.getSelectedItem().getValue())).getPersonId()).getUsername();
                        String practiceName = ((Practice) (practiceListbox.getSelectedItem().getValue())).getPracticeName();
                        String lessonName = ((Lesson) (lessonListbox.getSelectedItem().getValue())).getLessonName();
                        List<StudentReflection> reflections = studentService.getStudentReflection(s.getPersonId(), l.getLessonId());
                        TEMRUtil.pdfExport(studentName, practiceName, lessonName,  currentUser.getUsername(),  feeds, reflections);
                    }
                }); 
            //}

and this is the pdfExport method,

public static void pdfExport(String studentName, String practiceName, String lessonName, String currentUserName, List<studentreflectionfeedback> feeds, List<studentreflection> reflections ) throws IOException {

    //name of the file to be downloaded    
    String fileName = "studentReflectionNoteSummary" + "_" + studentName+ "_" +
            df.format(new Date())+ ".pdf" ; 
    //creates a temporary file in memory
    File temp = File.createTempFile("SRNFeedbackSummary", ".pdf");

    Document document = new Document();
    FileInputStream fileInputStream = null;
    try {

        PdfWriter.getInstance(document, new FileOutputStream( temp));
        document.open();

        //actual content of the file is constructed here
        document = addContent(document, studentName, practiceName, lessonName,   currentUserName, feeds, reflections );               
        document.close();                     

        //load the file
        //File file = new File(temp.getAbsolutePath()); 

        fileInputStream = new FileInputStream(temp.getAbsolutePath());


        temp.deleteOnExit();
        //zk filedownload
        Filedownload.save(fileInputStream, "application/pdf", fileName);


    } catch (Exception e) {            
        log.error("Error generating pdf ", e);
    }/*finally{
        fileInputStream.close();
    }*/


}

I don't see any errors either in the logs or on the ui. I just see some flickering effect on ui with vertical scroll bar added to the page. (looks like as if it is downloading but actual download is not happening)

link publish delete flag offensive edit

answered 2015-10-12 12:00:07 +0800

hmannam gravatar image hmannam
153 2

updated 2015-10-12 12:03:38 +0800

Also, this is the html source code i have noticed on chrome debug mode,

not sure why zk7 version is appending two more extra attributes (zxsrc and zxurl) in the html code. I am guessing that would be the problem. and can you pls tell me the purpose of those two attibutes?

zk7 version:

<iframe src="/tEMR/zkau/view/z_ifo/dwnmed-0/058/studentReflectionNoteSummary_STUDENT1_12-Oct-2015%2007:10.pdf" id="zk_download" name="zk_download" style="visibility:hidden;width:0;height:0;border:0" frameborder="0" z_xsrc="http://localhost:8080/tEMR/zkau/view/z_ifo/dwnmed-0/058/studentReflectionNoteSummary_STUDENT1_12-Oct-2015%2007:10.pdf" z_xurl="/tEMR/zkau/web/org/regenstrief/framework/ui/security/temr-login.zul"></iframe>

zk5 version:

<iframe src="/tEMR/zkau/view/z_fb5/dwnmed-0/egn1/studentReflectionNoteSummary_STUDENT1_12-Oct-2015%2007:10.pdf" id="zk_download" name="zk_download" style="visibility:hidden;width:0;height:0;border:0" frameborder="0"></iframe>
link publish delete flag offensive edit

answered 2015-10-12 12:18:04 +0800

Darksu gravatar image Darksu
1991 1 4

Hello hmannam,

Let's make it a little more simple:

try {
    File file = new File(fileName);
    Filedownload.save(file, null);
} catch (FileNotFoundException e) {
    e.printStackTrace();            
}

Please try this out, and let me know.

Best Regards,

Darksu

link publish delete flag offensive edit

answered 2015-10-12 12:43:39 +0800

hmannam gravatar image hmannam
153 2

updated 2015-10-12 12:44:47 +0800

Hi Darksu,

Tried below code and no luck. Noticed the same behavior,

try{ File file = new File(temp.getAbsolutePath()); Filedownload.save(file, null); } catch (Exception e) {
log.error("Error generating pdf ", e); }

link publish delete flag offensive edit

answered 2015-10-13 16:17:18 +0800

rickcr gravatar image rickcr
704 7

Side note, not sure if it's related because you're using a temp directory. But it's silly in my opinion just to make a temp file so that you can provide it to the end user (and then delete on exit.) Instead, we just have our service layer stream the file to a ByteArrayOutputStream and use toByteArray on it in the FileDownload.save. something like this for your stuff:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
yourPdfCreatorService.streamFile(paramsYouNeed, baos);
Filedownload.save(baos.toByteArray(), "application/pdf", "pdfName.pdf");

That being said, I also use ZK7 and Chrome without issues streaming back known files on the file system. Test it with a different known file - not one that you're trying to create in your system's temp dir. You also didn't post what Exception is being caught in your log.error section.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2015-10-09 14:48:04 +0800

Seen: 55 times

Last updated: Oct 13 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More