File uploads

View: New views
7 Messages — Rating Filter:   Alert me  

File uploads

by Oliver Epper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all !

I experience a little trouble with file uploads in grails.
Imagine a newly created app with the following domain-class:

class Picture {
  byte[] picture
}

Now, let's generate the controller and appropriate views
using grails generate-all Picture. I cannot upload any files, because
the controllers save method throws an exception while trying to
save the instance of the Picture class.
Long story short:
This happens because the params Map does not contain any
key-value pairs :(
The funny thing is: If I change the enctype-attribute in create.gsp
from "multipart/form-data" to "multipart/form" everything works
fine...
Hope anyone can explain that to me !!! (please)
I use Java 6, and groovy 1.0 and grails 0.4.1

--
Epper & Kranz GbR
Oliver Epper, Patrick Kranz
EK IT-Solutions
Südring 37
54634 Bitburg
Tel: +49 (0)6561 951614
Fax: +49 (0)6561 12425


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: File uploads

by graemer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Currently the scaffolding is not clever enough to know that a byte[]
requires an upload form, we plan to fix this one day

Cheers

On 2/21/07, Oliver Epper <oliver@...> wrote:

> Hi all !
>
> I experience a little trouble with file uploads in grails.
> Imagine a newly created app with the following domain-class:
>
> class Picture {
>   byte[] picture
> }
> Now, let's generate the controller and appropriate views
> using grails generate-all Picture. I cannot upload any files, because
> the controllers save method throws an exception while trying to
> save the instance of the Picture class.
> Long story short:
> This happens because the params Map does not contain any
> key-value pairs :(
> The funny thing is: If I change the enctype-attribute in create.gsp
> from "multipart/form-data" to "multipart/form" everything works
> fine...
> Hope anyone can explain that to me !!! (please)
> I use Java 6, and groovy 1.0 and grails 0.4.1
>
> --
> Epper & Kranz GbR
> Oliver Epper, Patrick Kranz
> EK IT-Solutions
> Südring 37
> 54634 Bitburg
> Tel: +49 (0)6561 951614
> Fax: +49 (0)6561 12425
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: File uploads

by felipenasc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You need to change the form tag to have the
enctype="multipart/form-data" attribute.

[]s
Felipe

On 2/21/07, Graeme Rocher <graemerocher@...> wrote:

> Currently the scaffolding is not clever enough to know that a byte[]
> requires an upload form, we plan to fix this one day
>
> Cheers
>
> On 2/21/07, Oliver Epper <oliver@...> wrote:
> > Hi all !
> >
> > I experience a little trouble with file uploads in grails.
> > Imagine a newly created app with the following domain-class:
> >
> > class Picture {
> >   byte[] picture
> > }
> > Now, let's generate the controller and appropriate views
> > using grails generate-all Picture. I cannot upload any files, because
> > the controllers save method throws an exception while trying to
> > save the instance of the Picture class.
> > Long story short:
> > This happens because the params Map does not contain any
> > key-value pairs :(
> > The funny thing is: If I change the enctype-attribute in create.gsp
> > from "multipart/form-data" to "multipart/form" everything works
> > fine...
> > Hope anyone can explain that to me !!! (please)
> > I use Java 6, and groovy 1.0 and grails 0.4.1
> >
> > --
> > Epper & Kranz GbR
> > Oliver Epper, Patrick Kranz
> > EK IT-Solutions
> > Südring 37
> > 54634 Bitburg
> > Tel: +49 (0)6561 951614
> > Fax: +49 (0)6561 12425
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>
> --
> Graeme Rocher
> Grails Project Lead
> http://grails.org
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: File uploads

by Oliver Epper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all ! Hi Graeme !

First of all thanks for your quick answer. Sorry, but I have to bother
you again.

Graeme Rocher schrieb:
> Currently the scaffolding is not clever enough to know that a byte[]
> requires an upload form, we plan to fix this one day
The scaffolding (command line) does generate a form that uses the
multipart/form-data
enctype and uses an input element with type file for the picture property.
In the controllers save method I can successfully call
request.getFile('picture') and the
result is a MultipartFile.
As far as I can see everything is fine, except that the following code:
picture.save() throws a hibernate exception, because setting the picture
property of
the picture class does not happen with picture.properties = params, because
params is an empty map :(

I don't think that it is a big problem that the scaffolding code does
not handle this
properly, but I don't get what the real problem is. What is missing ?
The form
is an upload form, the resulting request implements getFile(). I can
easily fix the
whole thing with a line like picture.setPicture(file.getBytes()). So why
is the
params Map empty. I'd like to help here if someone can give me a little
insight ;)

Thx in advance
Oliver

>
> Cheers
>
> On 2/21/07, Oliver Epper <oliver@...> wrote:
>> Hi all !
>>
>> I experience a little trouble with file uploads in grails.
>> Imagine a newly created app with the following domain-class:
>>
>> class Picture {
>>   byte[] picture
>> }
>> Now, let's generate the controller and appropriate views
>> using grails generate-all Picture. I cannot upload any files, because
>> the controllers save method throws an exception while trying to
>> save the instance of the Picture class.
>> Long story short:
>> This happens because the params Map does not contain any
>> key-value pairs :(
>> The funny thing is: If I change the enctype-attribute in create.gsp
>> from "multipart/form-data" to "multipart/form" everything works
>> fine...
>> Hope anyone can explain that to me !!! (please)
>> I use Java 6, and groovy 1.0 and grails 0.4.1
>>
>> --
>> Epper & Kranz GbR
>> Oliver Epper, Patrick Kranz
>> EK IT-Solutions
>> Südring 37
>> 54634 Bitburg
>> Tel: +49 (0)6561 951614
>> Fax: +49 (0)6561 12425
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: File uploads

by Oliver Epper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all !

Sorry to bother you all again, but I cannot believe that nobody
can give me a little insight here...

Oliver Epper schrieb:
> Hi all ! Hi Graeme !
>
> First of all thanks for your quick answer. Sorry, but I have to bother
> you again.
>
> Graeme Rocher schrieb:
>> Currently the scaffolding is not clever enough to know that a byte[]
>> requires an upload form, we plan to fix this one day
As I've already mentioned: The form IS an upload form !
Please give me a little more insight, so that I can understand why the
params
Map is empty :)

> The scaffolding (command line) does generate a form that uses the
> multipart/form-data
> enctype and uses an input element with type file for the picture
> property.
> In the controllers save method I can successfully call
> request.getFile('picture') and the
> result is a MultipartFile.
> As far as I can see everything is fine, except that the following code:
> picture.save() throws a hibernate exception, because setting the
> picture property of
> the picture class does not happen with picture.properties = params,
> because
> params is an empty map :(
>
> I don't think that it is a big problem that the scaffolding code does
> not handle this
> properly, but I don't get what the real problem is. What is missing ?
> The form
> is an upload form, the resulting request implements getFile(). I can
> easily fix the
> whole thing with a line like picture.setPicture(file.getBytes()). So
> why is the
> params Map empty. I'd like to help here if someone can give me a
> little insight ;)
>
> Thx in advance
> Oliver
>>
>> Cheers
>>
>> On 2/21/07, Oliver Epper <oliver@...> wrote:
>>> Hi all !
>>>
>>> I experience a little trouble with file uploads in grails.
>>> Imagine a newly created app with the following domain-class:
>>>
>>> class Picture {
>>>   byte[] picture
>>> }
>>> Now, let's generate the controller and appropriate views
>>> using grails generate-all Picture. I cannot upload any files, because
>>> the controllers save method throws an exception while trying to
>>> save the instance of the Picture class.
>>> Long story short:
>>> This happens because the params Map does not contain any
>>> key-value pairs :(
>>> The funny thing is: If I change the enctype-attribute in create.gsp
>>> from "multipart/form-data" to "multipart/form" everything works
>>> fine...
>>> Hope anyone can explain that to me !!! (please)
>>> I use Java 6, and groovy 1.0 and grails 0.4.1
>>>
>>> --
>>> Epper & Kranz GbR
>>> Oliver Epper, Patrick Kranz
>>> EK IT-Solutions
>>> Südring 37
>>> 54634 Bitburg
>>> Tel: +49 (0)6561 951614
>>> Fax: +49 (0)6561 12425
>>>
>>>
>>>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: File uploads

by felipenasc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Give us some code here.
How does you form look like?
How does your controller look like?

[]s
Felipe

On 2/23/07, Oliver Epper <oliver@...> wrote:

> Hi all !
>
> Sorry to bother you all again, but I cannot believe that nobody
> can give me a little insight here...
>
> Oliver Epper schrieb:
> > Hi all ! Hi Graeme !
> >
> > First of all thanks for your quick answer. Sorry, but I have to bother
> > you again.
> >
> > Graeme Rocher schrieb:
> >> Currently the scaffolding is not clever enough to know that a byte[]
> >> requires an upload form, we plan to fix this one day
> As I've already mentioned: The form IS an upload form !
> Please give me a little more insight, so that I can understand why the
> params
> Map is empty :)
>
> > The scaffolding (command line) does generate a form that uses the
> > multipart/form-data
> > enctype and uses an input element with type file for the picture
> > property.
> > In the controllers save method I can successfully call
> > request.getFile('picture') and the
> > result is a MultipartFile.
> > As far as I can see everything is fine, except that the following code:
> > picture.save() throws a hibernate exception, because setting the
> > picture property of
> > the picture class does not happen with picture.properties = params,
> > because
> > params is an empty map :(
> >
> > I don't think that it is a big problem that the scaffolding code does
> > not handle this
> > properly, but I don't get what the real problem is. What is missing ?
> > The form
> > is an upload form, the resulting request implements getFile(). I can
> > easily fix the
> > whole thing with a line like picture.setPicture(file.getBytes()). So
> > why is the
> > params Map empty. I'd like to help here if someone can give me a
> > little insight ;)
> >
> > Thx in advance
> > Oliver
> >>
> >> Cheers
> >>
> >> On 2/21/07, Oliver Epper <oliver@...> wrote:
> >>> Hi all !
> >>>
> >>> I experience a little trouble with file uploads in grails.
> >>> Imagine a newly created app with the following domain-class:
> >>>
> >>> class Picture {
> >>>   byte[] picture
> >>> }
> >>> Now, let's generate the controller and appropriate views
> >>> using grails generate-all Picture. I cannot upload any files, because
> >>> the controllers save method throws an exception while trying to
> >>> save the instance of the Picture class.
> >>> Long story short:
> >>> This happens because the params Map does not contain any
> >>> key-value pairs :(
> >>> The funny thing is: If I change the enctype-attribute in create.gsp
> >>> from "multipart/form-data" to "multipart/form" everything works
> >>> fine...
> >>> Hope anyone can explain that to me !!! (please)
> >>> I use Java 6, and groovy 1.0 and grails 0.4.1
> >>>
> >>> --
> >>> Epper & Kranz GbR
> >>> Oliver Epper, Patrick Kranz
> >>> EK IT-Solutions
> >>> Südring 37
> >>> 54634 Bitburg
> >>> Tel: +49 (0)6561 951614
> >>> Fax: +49 (0)6561 12425
> >>>
> >>>
> >>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: File uploads

by DashHunter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

To recreate the problem just create a simple Domain class

class Picture {
   byte[]  data
   String name
}

Then do a grails generate-all Picture
Try to create a new Picture. It will fail because property data is not bound.

I think I have found the cause of the problem and have raised an issue:

http://jira.codehaus.org/browse/GRAILS-838

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email