0

Fileupload problem - onUpload not fired, progressbar stucked at 100%

asked 2015-06-17 15:22:54 +0800

peda gravatar image peda
12 3

updated 2015-06-17 15:24:40 +0800

Hi all,

I'm using ZK 7.0.3 with Spring Security 3.2.7 on a Ubuntu Server with Java SDK 7 and Tomcat 8

Everything works fine, but I encounter a problem with ZK's file upload.

When uploading a file, the upload process gets 'stucked' when the process bar reaches 100%. From this time on, nothing happens.

My ZUL file

<zk>
  <div id="theParentDiv" apply="${myController}" vflex="1">
    <vlayout>
      <groupbox title="File upload" >
        <button id="fileUpload" upload="true" label="Upload" 
         image="somepic.png"/>              
      </groupbox>
    </vlayout>
  </div>
</zk>

My Controller

@Controller
@Scope("session")
public class MyController extends SelectorComposer<Component> {

  @Wire
  Button fileUpload;

  @AfterCompose
  public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    Selectors.wireComponents(view, this, false);
  }

  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);
// ...
  }

  // ...

  @Listen("onUpload=#fileUpload") 
  public void upload(UploadEvent event){            
    logger.info("upload event");  // NEVER REACHED
    final Media media = event.getMedia();
    if(media.isBinary()) {
      // complain
      return;
    }

    // process it
  }
}

When I look into the temp directory of my tomcat application on the server, I do see the uploaded file:

drwxrwxrwx 2 root root     4096 Jun 17 15:42 .
drwxr-sr-x 9 root staff    4096 Jun 17 15:15 ..
-rw------- 1 root root        8 Jun 17 15:42 imageio3741336634515839675.tmp
-rw-r--r-- 1 root root  1042112 Jun 17 15:42 upload_dea8c8ae_78f4_41a2_9481_b67144e339cf_00000000.tmp

I don't have a clue why the file upload gets stucked. Could the file permissions be the problem (Tomcat was started via 'sudo'; so I guess it is OK)?

The problem seems to be very similar to the one decribed here (no solution so far):

forum.zkoss.org/question/81047/uploadevent-is-not-triggering-after-file-upload/ (sorry, not enough karma for posting a link)

Just to mention: beside the above code I also tried a version with

<button id="fileUpload" label="Upload" />

and

@Listen("onClick=#fileUpload")  
public void justUpload() {
  Fileupload.get();
}

@Listen("onUpload=#theParentDiv")   
public void onceUploaded(UpdateEvent event) {
  // NEVER REACHED
  final Media media = event.getMedia();
  //
}

but I ran into the same issue.

Does anybody know a solution to this problem?

Kind regards, Peter

delete flag offensive retag edit

10 Answers

Sort by ยป oldest newest most voted
0

answered 2015-08-26 06:08:02 +0800

alexprawira gravatar image alexprawira
15

add this to your http configuration :

http.headers().addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN));
link publish delete flag offensive edit
2

answered 2015-09-02 09:06:20 +0800

peda gravatar image peda
12 3

updated 2015-10-21 13:52:37 +0800

Thank you alexprawira,

this solved the issue!

Regards, Peter

Edit: For ZK 7 with Spring Security 4.x the solution above does not work. Instead, add

http.headers().frameOptions().sameOrigin();

to your SecurityConfig.java file

link publish delete flag offensive edit

Comments

Hi Peter, i have the same issue, but i am not using SecurityConfig.java file , so what is the alternate

Senthilchettyin ( 2016-12-20 12:06:54 +0800 )edit
0

answered 2015-06-19 09:16:44 +0800

Darksu gravatar image Darksu
1991 1 4

Hello Peda,

First of all could you please use the code that is included at the following forum post? (It will work for all file types)

http://forum.zkoss.org/question/97558/fileupload-not-working/?answer=97561#post-id-97561

If it still does not work, i suspect it may be related with Spring security.

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2015-06-22 09:07:32 +0800

peda gravatar image peda
12 3

Hello Darksu,

thanks for you reply. I tried the code you suggested and again I ran into the same issue. So I think it's a Spring security issue (or at least a spring security config issue). I'll try to find a solution there ...

Regards, Peter

link publish delete flag offensive edit
0

answered 2015-06-22 12:34:35 +0800

Darksu gravatar image Darksu
1991 1 4

Hello peda,

Yes as mentioned before it probably is a spring security issue.

Could you please upload your spring configuration files so i can check them out?

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2015-06-23 13:26:10 +0800

peda gravatar image peda
12 3

Hello Darksu,

thank you very much for your help. Attached you can view my spring security settings.

Regards, Peter

web.xml (excerpt)

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/applicationContext.xml
        /WEB-INF/applicationContext-security.xml
    </param-value>
</context-param>

<listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
   <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="...">

    <context:annotation-config />
    <context:component-scan base-package="my.base.package.for.services" />       
</beans>

applicationContext-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="...">

   <global-method-security secured-annotations="enabled" />     
</beans:beans>

Spring Security Config

@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable();

        http.authorizeRequests()    
            .antMatchers("/login.zul").permitAll()
            .antMatchers("/css/**", "/images/**").permitAll()
            .antMatchers("widgets/**").access("hasAnyRole('USER', 'ADMIN', 'SUPERUSER')")
            .antMatchers("/index.zul").access("hasAnyRole('USER', 'ADMIN', 'SUPERUSER')")
            .antMatchers("/j_spring_security_check").anonymous()                

        .and()

    .formLogin()
        .permitAll()
            .usernameParameter("username") 
                .passwordParameter("password")
        .defaultSuccessUrl("/index.zul", true)
                .loginPage("/login.zul")
            .loginProcessingUrl("/j_spring_security_check")
                .failureUrl("/login.zul?error=1")
            .and()
                .rememberMe()
            .and()          
                .logout().logoutSuccessUrl("/login.zul").logoutUrl(
                "/j_spring_security_logout").invalidateHttpSession(true).permitAll();

        http.sessionManagement().sessionFixation().none();
    }

}

Spring security initalizer

public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {

// I also tried this, but without success
    /*
      @Override
      protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
        insertFilters(servletContext, new MultipartFilter());
      }
*/
}
link publish delete flag offensive edit
0

answered 2015-06-24 10:48:08 +0800

queiccy gravatar image queiccy
1
http://www.damianpoleca.p...

Whoa it totally works ;)

link publish delete flag offensive edit
0

answered 2015-08-05 08:04:37 +0800

peda gravatar image peda
12 3

I still did not figure out why the above code is not working for me and what I could do to enable the file upload. So if some one has some advices/recommendations I would be very pleased.

Kind regards, Peter

link publish delete flag offensive edit
0

answered 2018-06-29 14:13:28 +0800

distelka gravatar image distelka
68 1

Hello did you find a solutions ? Could you share it.I have the same problem .....

link publish delete flag offensive edit
0

answered 2020-02-12 19:20:46 +0800

lccp gravatar image lccp
3

@alexprawira, thank you a lot. It is working. I'm using XML based config, so I've added:

<http auto-config="true">
...
<headers>
    <frame-options policy="SAMEORIGIN" />
</headers>
...
link publish delete flag offensive edit
Your answer
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
3 followers

RSS

Stats

Asked: 2015-06-17 15:22:54 +0800

Seen: 133 times

Last updated: Feb 12 '20

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