2

I am using SWFUpload to upload files to java servlet (spring framework). The problem is that the current web session is lost during file upload (it creates a new session). I read that it is a known bug and there are some workarounds somewhere but I can't find anything. Does anyone know how to make it work?

Thanks.

serg
  • 109,619
  • 77
  • 317
  • 330

3 Answers3

5

Have a look at this post on the SWFUpload forums. Adding ;jsessionid=XXX to the upload URL may work for you, or it may not; the exact cause of the problem appears unclear. Note that Flash uses the Wininet stack (same as IE), so if you are using a different browser you need to somehow get the session cookie (known to your browser) into the IE cookie.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
  • This is certainly a potential solution if your web server supports it (most Java Containers do allow session id in the querystring). – Keith Adler Jul 20 '09 at 18:34
  • What doesn't work, exactly? Note that my suggestion uses a semicolon rather than ? to add the session data - did you use this? What does your URL look like? – Vinay Sajip Jul 20 '09 at 19:08
  • Actually it works in IE (even without jsession) but not in FF. You said: somehow get the session cookie (known to your browser) into the IE cookie. How would I do that? – serg Jul 20 '09 at 19:16
  • By adding `;jsessionid=XXX` to the URL :-) – Vinay Sajip Jul 20 '09 at 19:43
  • I tried that but it doesn't help. I also tried to pass all cookies through SWFUpload.post_params but it still doesn't work. – serg Jul 20 '09 at 19:50
  • Can I somehow get session by id in java? Lets say I just pass sessionid as a regular parameter, can I access this session by id? There used to be HttpSessionContext but it is deprecated now without a replacement. – serg Jul 20 '09 at 19:56
  • Can you show the actual URL which is being passed (and which includes the `;jsessionid=XXX`? – Vinay Sajip Jul 20 '09 at 19:57
  • /fileUpload.html;jsessionid=8EB0F94EB5E5C17FECD3787743B2ED20 – serg Jul 20 '09 at 20:02
  • So, I assume fileUpload.html maps to a servlet, right? What do you see in the servlet which is handling the POST request when you try to get the session? – Vinay Sajip Jul 20 '09 at 20:03
  • Right. What exactly are you interested in? I see there new sessionid. org.springframework.web.multipart.MultipartHttpServletRequest is what my request is. Request params contain "upload" and "filename" attributes from sfwupload. – serg Jul 20 '09 at 20:13
  • I'm thinking about the request headers, particularly the *Cookie* header. Presumably there is a session cookie in the request headers which is being used to map to the "other" session. You may have to resort to removing this cookie somehow so that there's only one session ID. Also worth confirning that the session cookie name actually _is_ `jsessionid`. What servlet container are you using? – Vinay Sajip Jul 21 '09 at 07:12
  • If session cookie was there I wouldn't have any problems in the first place I think. Session name is JSESSIONID (I tried it as well). – serg Jul 21 '09 at 16:22
  • I'm not sure what servlet container you're using, so I'm not sure where it looks for a session ID. Normally it would be either in the URL or in a cookie; if you are supplying it in the URL, either it's getting a different value from a cookie and using that, or it's configured to ignore session IDs passed in the URL. Seems somewhat container-specific at the moment. – Vinay Sajip Jul 21 '09 at 17:50
0

Had this on the .NET platform as well. The problem is that the Flash Object runs in a different session context than your Java App (it's effectively treated like a new client). One way to get around all of this is to effectively have the object post any necessary information needed to commit the uploads back in the querystring.

Keith Adler
  • 20,880
  • 28
  • 119
  • 189
0

The known bug you describe sounds like this one. If you have the time please sign up just to say "I have this problem too" so we can make it really clear to Adobe that it is affecting a lot of people.

It is hard to give an example of the best way to do it for your particular situation as I don't know much about spring.

That said, the usual way to work around it is to append a GET variable with the session to the upload url, then take that and manually set it to be the session on the server-side.

Here's another SO thread about this problem that has a good answer (unfortunately not specific to java+spring, but might give you a better idea).

Hopefully that's enough detail to get you off to a good start.

Community
  • 1
  • 1
Nick Knowlson
  • 7,185
  • 6
  • 47
  • 63