Re: SISCweb & File Upload

"Gerardo Horvilleur" <[email protected]> Tue, 22 Jul 2008 22:21:52 -0500
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
The truth is that I didn't look too deeply into the character encoding
problem. I just did a quick scan of the apache file upload library
javadocs, and as I didn't find immediately something that seemed to
solve my problem then I just skipped right ahead into thinking what
was the easiest to implement workaround. I am slightly behind schedule
on this iteration for my project and I just wanted to have file upload
working so  I could be able to start working on the other features I
need to deliver this week :)

By the way, being able to telnet into a REPL running right inside my
webapp has been very useful in developing this application.

On Tue, Jul 22, 2008 at 9:29 PM, Alessandro Colomba <[email protected]> wrote:
> Gerardo,
>
> I'm glad to hear that, and thank you for posting your solution.
>
> If you don't mind, I'd like to ask you about the character encoding. I
> would imagine you could read the character encoding of the request and
> then use that when reading the parameters, much like the standard
> (get-binding) does. Is there a reason that was not possible in your
> case?
> ___
> Alessandro
>
>
>
>
>
> On Tue, Jul 22, 2008 at 2:05 AM, Gerardo Horvilleur <[email protected]> wrote:
>> That's exactly what I did :)
>> I wrote my own (get-upload-bindings), and I found the util/misc module
>> which has been very useful!
>>
>> I just got it to work about a couple of minutes ago.
>>
>> Some of the problems I had to solve:
>>
>> 1. If the request is not in multipart format then the
>> ServletFileUpload.parseRequest() throws an exception. So my
>> (get-upload-bindings) first checks if the request is in multipart
>> format, and if it isn't then it delegates the work to the standard
>> (get-bindings). I need this because I have a "Cancel" link on my form
>> which won't send the request data in multipart format.
>>
>> 2. I have some fields where the name is not in 7 bit ascii (it is a
>> content management system where the users can define the fields that
>> need to be entered for each kind of entity, and they assign the names
>> they want to each field they create), and the file upload library does
>> not handle those names correctly. To work around this, I wrote some
>> code to create an "external" name which only uses 7 bit ascii
>> characters for each field name.
>>
>> 3. The file upload library seems unable to handle multiple checkboxes
>> with the same name, it just returns the value of the last checked
>> checkbox. So it is impossible to have (get-upload-bindings) return a
>> list of values. It turns out I never need to have both file uploads
>> and multiple checkboxes with identical names in the same web page for
>> my application. So I did not have to solve this problem :)
>>
>> On Mon, Jul 21, 2008 at 11:52 PM, Alessandro Colomba <[email protected]> wrote:
>>> Gerardo,
>>>
>>> You're right, I had forgotten that in J2EE the
>>> HttpServletRequest.getParameter*() methods don't handle multipart
>>> requests.
>>>
>>> The FileUtil library however allows you to read that information with
>>> the readHeaders() call. It's a bit clunky, with Iterators and the
>>> such, but consider that:
>>>
>>> 1) The (get-bindings) procedure returns a plain Java Map as per [1].
>>> This is not ever going to change.
>>>
>>> 2) You can implement your (get-bindings/multipart) procedure either as
>>> a wrapper around some Java code that extracts a parameter Map from the
>>> FileUpload MultiPartstream, or directly, and somewhat naturally, using
>>> the (iterator/for-each) procedures in the util/misc module. [2]
>>>
>>> Sorry this couldn't be any simpler.
>>> ___
>>> Alessandro
>>>
>>> [1] http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#getParameterMap()
>>>
>>> [2] http://siscweb.cvs.sourceforge.net/siscweb/siscweb/scm/util/misc.scm?revision=1.4&view=markup&pathrev=rel-0-6-dev
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Jul 21, 2008 at 3:27 AM, Gerardo Horvilleur <[email protected]> wrote:
>>>> I've been doing a few tests and I have a problem. In order to be able
>>>> to upload files y must declare the form's enctype to be
>>>> multipart/form-data:
>>>>
>>>> (form (@ (action ,k-url) (enctype multipart/form-data)) ...
>>>>
>>>> But, once I do this, get-bindings isn't able anymore to extract the
>>>> bindings from the request object. It just returns an empty map.
>>>>
>>>> On Sun, Jul 20, 2008 at 11:16 PM, Alessandro Colomba <[email protected]> wrote:
>>>>> Gerardo,
>>>>>
>>>>> The request object returned by the some of the send-*/* procedures is
>>>>> the actual HttpServletResponset object. You can most certainly place
>>>>> more than one call to it.
>>>>>
>>>>> The response object is also always available through the
>>>>> (current-response) procedure in the siscweb/response module. [*] So
>>>>> your file upload module does not technically need to be passed the
>>>>> response object, and you can keep the (get-bindings) call n place.
>>>>>
>>>>> Hope this helps,
>>>>> ___
>>>>> Alessandro
>>>>>
>>>>> [*] http://siscweb.sourceforge.net/swm/ch08.html#response
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Jul 20, 2008 at 1:38 AM, Gerardo Horvilleur <[email protected]> wrote:
>>>>>> The Apache Commons File Upload library is what I have used in other
>>>>>> projects written in Java.
>>>>>>
>>>>>> So, it looks like I''ll have to do something like
>>>>>>
>>>>>> (let ((request (send-thml/suspend ...
>>>>>>
>>>>>> instead of doing
>>>>>>
>>>>>> (let ((bindings (get-bindings (send-html/suspend ...
>>>>>>
>>>>>> so I can give the request to the file upload library to extract the data.
>>>>>>
>>>>>> What I don't know is if, after I've used the request object with the
>>>>>> file upload library, I still can do a a
>>>>>>
>>>>>> (let ((bindings (get-bindings request))) ...
>>>>>>
>>>>>> To extract the values for the parameters which are not file uploads.
>>>>>>
>>>>>> All the pages in which I need to support file uploads also have many
>>>>>> other fields, and I would like to still be able to use get-bindings to
>>>>>> handle them.
>>>>>>
>>>>>> On Sat, Jul 19, 2008 at 8:31 PM, Alessandro Colomba <[email protected]> wrote:
>>>>>>> Gerardo,
>>>>>>>
>>>>>>> Unfortunately file uploads in J2EE are best handled through
>>>>>>> third-party libraries, and I really did not want to tie SISCweb to
>>>>>>> one. Apache Commons has a pretty good library (FileUpload), and I
>>>>>>> wouldn't imagine difficult to write a Scheme wrapper around it.
>>>>>>>
>>>>>>> Should you decide to go this route, and encounter any obstacles in
>>>>>>> SISCweb, please let me know. I'll be glad to clear them out.
>>>>>>>
>>>>>>> Regards,
>>>>>>> ___
>>>>>>> Alessandro
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sat, Jul 19, 2008 at 6:14 PM, Gerardo Horvilleur <[email protected]> wrote:
>>>>>>>> For the application I'm writing, I need to let the user upload images
>>>>>>>> to the server. I haven't found any straightforward way to handle file
>>>>>>>> uploads in SISCweb. Has anybody already written some code to handle
>>>>>>>> this?
>>>>>>>>
>>>>>>>> --
>>>>>>>> Gerardo Horvilleur
>>>>>>>> [email protected]
>>>>>>>> 5813-0830
>>>>>>>>
>>>>>>>> -------------------------------------------------------------------------
>>>>>>>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>>>>>>>> Build the coolest Linux based applications with Moblin SDK & win great prizes
>>>>>>>> Grand prize is a trip for two to an Open Source event anywhere in the world
>>>>>>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>>>>>>> _______________________________________________
>>>>>>>> Sisc-users mailing list
>>>>>>>> [email protected]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/sisc-users
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Gerardo Horvilleur
>>>>>> [email protected]
>>>>>> 5813-0830
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Gerardo Horvilleur
>>>> [email protected]
>>>> 5813-0830
>>>>
>>>
>>
>>
>>
>> --
>> Gerardo Horvilleur
>> [email protected]
>> 5813-0830
>>
>



-- 
Gerardo Horvilleur
[email protected]
5813-0830

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/