0

Upload-Error "contentId is required!"

asked 2011-07-19 09:46:00 +0800

PhilipPeinsold gravatar image PhilipPeinsold
70 2

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!

delete flag offensive retag edit

4 Replies

Sort by » oldest newest

answered 2011-07-19 12:14:52 +0800

marcelodecampos gravatar image marcelodecampos
183

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;
    }



Or maybe these threads may help: http://www.zkoss.org/forum/listComment/16885-Fileupload or http://www.zkoss.org/forum/listComment/16722-AImage-from-binary-file

link publish delete flag offensive edit

answered 2012-01-06 07:25:01 +0800

drichm gravatar image drichm
15

In case anyone is interested.

I had this problem. In my case was due to the directory pointed to by the java.io.tmpdir system property not existing. Create the directory and it works fine.

Dave

link publish delete flag offensive edit

answered 2013-05-24 07:58:04 +0800

urenpatelce gravatar image urenpatelce flag of India
0

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

link publish delete flag offensive edit

answered 2017-04-01 08:31:07 +0800

z155096552 gravatar image z155096552
42 1

what is Solution?

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: 2011-07-19 09:46:00 +0800

Seen: 612 times

Last updated: Apr 01 '17

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