-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi!
Could someone explain to me the Errormessage "contentId is required!".
If I upload for example a picture I often get this Errormessage - not everytime, but really often!
I make the upload like this:
this.buttonImageUpload.addEventListener("onUpload", new org.zkoss.zk.ui.event.EventListener () { @Override public void onEvent(org.zkoss.zk.ui.event.Event arg0)throws Exception { UploadEvent event = (UploadEvent) arg0; media = event.getMedia(); } }
That's how my upload-button in the .zul looks like:
<button id="buttonImageUpload" upload="true" label="Bild hochladen" width="200px"/>
Did I something wrong here?
Thanks!
Hi, you can try this ( change MediaDTO to some byte[] after all)!
public static MediaDTO getMedia( org.zkoss.util.media.Media media ) throws IOException { MediaDTO dto = new MediaDTO(); int mediaSize = 1; dto.setFormat( media.getFormat() ); dto.setName( media.getName() ); dto.setMimeType( media.getContentType() ); if ( media.inMemory() ) { if ( media.isBinary() ) dto.setObject( media.getByteData() ); else dto.setObject( media.getStringData().getBytes( "UTF-8" ) ); } else { if ( media.isBinary() ) { mediaSize = media.getStreamData().available(); dto.setObject( new byte[ mediaSize ] ); media.getStreamData().read( dto.getObject(), 0, mediaSize ); } else { InputStreamReader is = ( InputStreamReader )media.getReaderData(); StringBuffer strBuffer = new StringBuffer( 1024 * 64 ); char[] chArray = new char[ 512 ]; int nRead; do { nRead = is.read( chArray ); if ( nRead > 0 ) { strBuffer.append( chArray, 0, nRead ); } } while ( nRead > 0 ); mediaSize = strBuffer.length(); dto.setObject( strBuffer.toString().getBytes( "UTF-8" ) ); } } return dto; }
Hey Guys,
Waht dave found is correct.. I hit the same sort of issue on production while working with file uploading and I found that java.io.tmpdir doesn't have enough permission on my server to create temp file. So When i applied the full permission to that tmpdir then it fixes this contentid issue. Basically ZK is not returning very meaningful message so its tough to track this issue. Please check tmpdir first if anyone is facing this issue.
Uren Patel
what is Solution?
Asked: 2011-07-19 09:46:00 +0800
Seen: 612 times
Last updated: Apr 01 '17