UrlMapping and filename extensions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

UrlMapping and filename extensions

sbglasius
Hi,

I have the following url-mapping:

 name a: "/a/$file" {
     controller = 'attachment'
     action = 'get'
 }
and I want to use it like this

  <g:link mapping="a" params="[file: name]">${name}</g:link>

Where name could be: "myfile.pdf"

Problem is, when I get to my controller, Grails strips the extension, so I get

  params.file == "myfile"

Where I would like "myfile.pdf" to be able to search for the full file name in my domain objects.

I have tried to set

   grails.mime.file.extensions = false

But then all my controllers using "withFormat" is not working. Is there a way, where I can find the value of the full filename or alternatively the extension, which Grails has stripped?

Med venlig hilsen / Best regards,
Søren Berg Glasius

Hedevej 1, Gl. Rye, DK-8680 Ry, Denmark
P: (+45)87880170, M: (+45)40449188, S: sbglasius
--- Press ESC once to quit - twice to save the changes.
Reply | Threaded
Open this post in threaded view
|

Re: UrlMapping and filename extensions

Ian Roberts
On 08/02/2011 11:52, Søren Berg Glasius wrote:
> Is there
> a way, where I can find the value of the full filename or alternatively
> the extension, which Grails has stripped?

If all else fails there's request.forwardURI, which gives you the full
/a/myfile.pdf path (I can't remember offhand whether or not it includes
the context path on the front, i.e. /myapp/a/myfile.pdf, you'll have to
experiment).

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: UrlMapping and filename extensions

sbglasius
Hi Ian,

I asked the same question on stackoverflow and got this solution, that I want to share with you:

name a: "/a/$file**" {
     controller = 'attachment'
     action = 'get'
 }

Simply adding two stars did the trick. Just thought that I'd share it.

Med venlig hilsen / Best regards,
Søren Berg Glasius

Hedevej 1, Gl. Rye, DK-8680 Ry, Denmark
P: (+45)87880170, M: (+45)40449188, S: sbglasius
--- Press ESC once to quit - twice to save the changes.


2011/2/8 Ian Roberts <[hidden email]>
On 08/02/2011 11:52, Søren Berg Glasius wrote:
> Is there
> a way, where I can find the value of the full filename or alternatively
> the extension, which Grails has stripped?

If all else fails there's request.forwardURI, which gives you the full
/a/myfile.pdf path (I can't remember offhand whether or not it includes
the context path on the front, i.e. /myapp/a/myfile.pdf, you'll have to
experiment).

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: UrlMapping and filename extensions

Ian Roberts
On 09/02/2011 09:39, Søren Berg Glasius wrote:

> Hi Ian,
>
> I asked the same question on stackoverflow and got this solution, that I
> want to share with you:
>
> name a: "/a/$file**" {
>      controller = 'attachment'
>      action = 'get'
>  }
>
> Simply adding two stars did the trick. Just thought that I'd share it.

That will also allow slashes in $file, i.e. it will permit
/a/foo/bar/file.pdf.  This may or may not be a good thing depending on
your application.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: UrlMapping and filename extensions

sbglasius
> name a: "/a/$file**" {
>      controller = 'attachment'
>      action = 'get'
>  }
>
> Simply adding two stars did the trick. Just thought that I'd share it.

That will also allow slashes in $file, i.e. it will permit
/a/foo/bar/file.pdf.  This may or may not be a good thing depending on
your application.

You're right, but in my case its not a problem, as the file lives in a database and not in the filesystem. Thus, if someone enters a filename with slashes they will get a "404 Not found"
 
Med venlig hilsen / Best regards,
Søren Berg Glasius

Hedevej 1, Gl. Rye, DK-8680 Ry, Denmark
P: (+45)87880170, M: (+45)40449188, S: sbglasius
--- Press ESC once to quit - twice to save the changes.