|
From: Andy D. <an...@ma...> - 2005-03-03 17:07:20
|
I'm wondering if there are any plans on adding some kind of mime type to org.springframework.core.io.Resource? If I load a resource whose type I don't know in advance, I currently have no way to tell what type it is other than parsing the file name for an extension or attempting to deduce it from the InputStream (not fun). Thanks, Andy |
|
From: Matt S. <sga...@us...> - 2005-03-03 18:39:53
|
The mime type support in Spring is based on the mime type support in the Java Activation Framework. There are plans to add additional MIME types to Spring. See: http://opensource.atlassian.com/projects/spring/browse/SPR-637 Does this answer your question? Matt Andy Depue wrote: > I'm wondering if there are any plans on adding some kind of mime type to > org.springframework.core.io.Resource? If I load a resource whose type I > don't know in advance, I currently have no way to tell what type it is other > than parsing the file name for an extension or attempting to deduce it from > the InputStream (not fun). > > Thanks, > Andy > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click |
|
From: Andy D. <an...@ma...> - 2005-03-03 18:54:19
|
=46rom what I can tell, this appears to be related to JavaMail? If so, it = is=20 not what I need. I'm using Spring's Resource interface to access, well,=20 general resources. Some of these resources actually end up residing on a w= eb=20 server, and may even have a .jsp file extension - even though the .jsp page= =20 might end up generating a binary file of some specific mime type, which=20 the .jsp page will manually set on output. In this case I cannot rely on=20 file extension. It would be useful if the Resource interface could expose = to=20 me a simple way to inspect the mime type. If it is a classpath/file/simple= =20 resource, then it could use the activation framework and detect the mime ty= pe=20 by the file extension (hiding all the gory details from me) - if it is a=20 Resource loaded from a web server, then it could return the mime type that= =20 was returned by the web server - and so on. Am I approaching this the wron= g=20 way? - Andy On Thursday 03 March 2005 10:12 am, Matt Sgarlata wrote: > The mime type support in Spring is based on the mime type support in the > Java Activation Framework. There are plans to add additional MIME types > to Spring. See: > > http://opensource.atlassian.com/projects/spring/browse/SPR-637 > > Does this answer your question? > > Matt |
|
From: Matt S. <sga...@us...> - 2005-03-04 15:23:13
|
OK, I see what you're getting at now. The problem is, how do you want Spring to figure out the mime type if it's not based on file extension? By dynamically inspecting the contents of the file at runtime? I know that's possible because IE does it, but that seems like it would be a pain to implement. Is there some other approach you could take, like storing the mime type information external to the file itself? Matt Andy Depue wrote: > From what I can tell, this appears to be related to JavaMail? If so, it is > not what I need. I'm using Spring's Resource interface to access, well, > general resources. Some of these resources actually end up residing on a web > server, and may even have a .jsp file extension - even though the .jsp page > might end up generating a binary file of some specific mime type, which > the .jsp page will manually set on output. In this case I cannot rely on > file extension. It would be useful if the Resource interface could expose to > me a simple way to inspect the mime type. If it is a classpath/file/simple > resource, then it could use the activation framework and detect the mime type > by the file extension (hiding all the gory details from me) - if it is a > Resource loaded from a web server, then it could return the mime type that > was returned by the web server - and so on. Am I approaching this the wrong > way? > > - Andy |
|
From: Andy D. <an...@ma...> - 2005-03-04 18:20:15
|
Well, actually, here is what I was thinking. Say that I pull a resource from
a file or classpath (file: or classpath: or even just a relative path).
Then, sure, just figure out the mime type based on file extension when I call
"getMimeType" (or whatever) against the Resource. That at least saves me the
trouble of parsing the filename or calling into the activation framework.
BUT, if I pass in a URL to a resource where the mime type is handled
independently of the filename (such as a "http:" URL, where the server will
return a type header), then return the specific mime type that was returned
by the server. See URL.openConnection().getContentType(). A simple
algorithm could be:
getMimeType() {
return URL.openConnection().getContentType() if not null,
otherwise parse filename/use activation framework.
}
- Andy
On Friday 04 March 2005 07:01 am, Matt Sgarlata wrote:
> OK, I see what you're getting at now. The problem is, how do you want
> Spring to figure out the mime type if it's not based on file extension?
> By dynamically inspecting the contents of the file at runtime? I know
> that's possible because IE does it, but that seems like it would be a
> pain to implement. Is there some other approach you could take, like
> storing the mime type information external to the file itself?
>
> Matt
|
|
From: Matt S. <sga...@us...> - 2005-03-04 19:33:32
|
Sounds reasonable to me. You should probably add an enhancement request
to JIRA.
Matt
Andy Depue wrote:
> Well, actually, here is what I was thinking. Say that I pull a resource from
> a file or classpath (file: or classpath: or even just a relative path).
> Then, sure, just figure out the mime type based on file extension when I call
> "getMimeType" (or whatever) against the Resource. That at least saves me the
> trouble of parsing the filename or calling into the activation framework.
> BUT, if I pass in a URL to a resource where the mime type is handled
> independently of the filename (such as a "http:" URL, where the server will
> return a type header), then return the specific mime type that was returned
> by the server. See URL.openConnection().getContentType(). A simple
> algorithm could be:
>
> getMimeType() {
> return URL.openConnection().getContentType() if not null,
> otherwise parse filename/use activation framework.
> }
>
> - Andy
>
> On Friday 04 March 2005 07:01 am, Matt Sgarlata wrote:
>
>>OK, I see what you're getting at now. The problem is, how do you want
>>Spring to figure out the mime type if it's not based on file extension?
>> By dynamically inspecting the contents of the file at runtime? I know
>>that's possible because IE does it, but that seems like it would be a
>>pain to implement. Is there some other approach you could take, like
>>storing the mime type information external to the file itself?
>>
>>Matt
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
|