0

Method filedownload.save(byte[] content, String contentType, String flnm) is not working

asked 2010-07-16 03:55:50 +0800

mikelara gravatar image mikelara
144
www.mextisa.com.mx

Hi all.

I need to let the user to recolect a file coming from a blob in Database. Problem is that
Filedownload.save(byte[] content, String contentType, String flnm) method does not seem to work. It results in a blank or broken file.

Here is my code.

    public void onClick$btnrecuperar(Event event){
        byte[] fileb = null;
        try {
            Documentos requestDocto = (Documentos) (listadoctos.getSelectedItem().getValue());
            int iddocumento = (requestDocto).getDocumentosPK().getIddocumento();
            int iddocente = (requestDocto).getDocumentosPK().getIddocente();
            fileb = dao.getDoctoFromDBAsBytes(iddocumento);
            Documentos retDocto = daodoctos.findDocumentos(new DocumentosPK(iddocumento, iddocente));

            Filedownload fdl = new Filedownload();             
            fdl.save(fileb, retDocto.getMimetype(), retDocto.getNombrearchivo());
            

        } catch (Exception ex) {
            Logger.getLogger(DocenteController.class.getName()).log(Level.WARNING, null, ex);
        }
    }



One coment is that i can accomplish this if i first create a temp file and then call Filedownload.save(myfile, null).
However if (and for many reasons i need to do so) i attempt to save the file as byte array, it simply don´t work, giving me a file filled with blanks o strange content unreadable for human o any application.

Any help will be really appreciated since i haven´t figured out what i am doing wrong yet. Thanks in advance.

Mike

delete flag offensive retag edit

10 Replies

Sort by » oldest newest

answered 2010-07-16 04:03:40 +0800

mikelara gravatar image mikelara
144
www.mextisa.com.mx

By the way. I am using version 3.6.3

link publish delete flag offensive edit

answered 2010-07-16 12:41:24 +0800

mikelara gravatar image mikelara
144
www.mextisa.com.mx

updated 2010-07-16 16:47:44 +0800

Hi

Any help or comments on this topic?.

I also tested my libs and the problem persist with ZK 3.6.4 (the latest update for ZK 3.6).
Am I not understanding how it's supposed to work? Please someone can help me?.

Mike

link publish delete flag offensive edit

answered 2010-07-18 20:06:17 +0800

PeterKuo gravatar image PeterKuo
481 2

You may reduce to most simple zul, to find the bug.
I tested following code in ZK live demo(which is zk 5)
and found no issue.

<button label="test">
<attribute name="onClick">
<![CDATA[
byte[] fileb = {0xaa,0xbb,0xcc};
Filedownload fdl = new Filedownload();
fdl.save(fileb, "text/plain", "test.txt");
]]>
</attribute>
</button>

link publish delete flag offensive edit

answered 2010-07-18 23:24:52 +0800

mikelara gravatar image mikelara
144
www.mextisa.com.mx

updated 2010-07-19 10:36:12 +0800

Thanks for your reply PeterKuo.

Did your code worked with 3.6 also?. The application uses ZK version 3.6.3, if i change the version to 5.0 other components work differently or have different license issues (eg. caledar).
I will try your sample code, but i don´t see the difference or what i am doing wrong. it makes me suspect it is a bug on ZK.

link publish delete flag offensive edit

answered 2010-07-19 20:06:25 +0800

PeterKuo gravatar image PeterKuo
481 2

I tested in zk 3.6.3 and it work.
You may use notepad++ with hex editor to see if the content of file is identical to your byte array.

link publish delete flag offensive edit

answered 2010-07-20 14:07:39 +0800

mikelara gravatar image mikelara
144
www.mextisa.com.mx

updated 2010-07-20 14:12:34 +0800

@PeterKuo

Yes. I already did that, that is why i wrote before that this method is giving me a file filled with blanks or strange content unreadable for human o any application. It creates the file with the correct size (to the original i stored in database), but the content is broken (there is content, just not readable as it is supposed to be).

It only happens with this method signature, the other one Filedownload.save(afile, contenttype) works, but is not the best in terms of application maintenance. I want to use the filedownload.save(byte[] content, String contentType, String flnm) since i store byte[] in the database.

Mike

link publish delete flag offensive edit

answered 2010-07-20 15:22:54 +0800

jj gravatar image jj
638 3

mike,
It is strange that one of the download signature works for you, but not the other. The underlying implementations would be the same, I assume.
I am using filedownload.save(Inputstream in, String contentType, String flnm) myself with 3.6.x and it has been working fine for me.
I also store my document in database as Blob, but different than what you did, I am using the Inputstream retrieved through JDBC, not putting it into bytes first.
You might have a bug somewhere when you use the above method, though I can't seem to see it from your sample code.

link publish delete flag offensive edit

answered 2010-07-20 17:20:41 +0800

mikelara gravatar image mikelara
144
www.mextisa.com.mx

updated 2010-07-20 17:22:04 +0800

Yes it was JJ, but i finally managed to solve it. It turned out that in this other execution path (precisely on fileb = dao.getDoctoFromDBAsBytes(iddocumento);
call), there was bug on my side at the persistence layer that created the byte array correctly (which explains why i ended up with a file of correct size), but it never filled out this byte[] with the content coming from the database.

Thanks to all for their comments, and to help me find my mistake, i hope i can return the favor some day soon.

Mike

link publish delete flag offensive edit

answered 2012-07-05 14:27:54 +0800

zzxstudynumber gravatar image zzxstudynumber
12

So big bug filedownload!!! I use it ,can't with fusionCharts,I think it's save method maybe have a bug.....

link publish delete flag offensive edit

answered 2012-09-11 05:50:09 +0800

paowang gravatar image paowang
140 6

@zzxstudynumber
Can you provide some code for reproducing your situation?

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

RSS

Stats

Asked: 2010-07-16 03:55:50 +0800

Seen: 491 times

Last updated: Sep 11 '12

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