-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
By the way. I am using version 3.6.3
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
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>
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.
@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
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.
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
So big bug filedownload!!! I use it ,can't with fusionCharts,I think it's save method maybe have a bug.....
Asked: 2010-07-16 03:55:50 +0800
Seen: 493 times
Last updated: Sep 11 '12