You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "s.marjanovic" <sl...@gmail.com> on 2015/09/02 14:01:27 UTC

How to get the file name from an http post submitted to jetty endpoint ?

Hello,

I'm creating a route that is supposed the accept an HTTP POST with a file
and, among other things, archive that file. My route is as shown below:

    from("jetty:http://{{host}}?httpMethodRestrict=POST").routeId("MyRoute")
         .to("file:"+"{{localArchiveFile}}")
         .unmarshal().zipFile()
         .convertBodyTo(String.class)
         .inOnly("amq:queue:MyQueue?timeToLive={{timetolive}}");

Stream cache is enabled on camel context level.

The problem I have is that file gets archived as something like ".134216472"
(a dot plus current system time).

Here's the filename pattern for inspection:
/data/archive/?fileName=${date:now:yyyyMMdd}/${file:onlyname}.${date:now:HHmmssSSS}

I'd like to avoid this and save the file with it's original name with
appended timestamp. I have inspected the exchange in debugger but I don't
see the filename in in.headers or in.request. Is there a way that I'm
missing that would enable me to get to the filename?

Kind regards,
Slavisa Marjanovic






--
View this message in context: http://camel.465427.n5.nabble.com/How-to-get-the-file-name-from-an-http-post-submitted-to-jetty-endpoint-tp5771156.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to get the file name from an http post submitted to jetty endpoint ?

Posted by "s.marjanovic" <sl...@gmail.com>.
Hello Andrew,

Thank you for your input. I figured out about the content-disposition header
myself but it wasn't available and I couldn't have been sure if I could ever
expect it from the party that was sending the post. Anyway, the employer
decided not to archive the zip but the unzipped contents though so it's fine
now since in that case the filename is not missing. Thanks for the tips
though, I'll be sure to remember :)

Kind regards,
Slavisa Marjanovic



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-get-the-file-name-from-an-http-post-submitted-to-jetty-endpoint-tp5771156p5771201.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to get the file name from an http post submitted to jetty endpoint ?

Posted by Andrew Block <an...@gmail.com>.
Slavisa,

Since the Jetty component exposes an endpoint, there is no implicit assumption that the request will be a file so there is no built in functionality for this purpose. You can still determine the name of the file being uploaded as it is passed along in the request in the content-disposition HTTP header. You an use a bean to to parse the filename from this header and set another header that can be used in your file endpoint.

This reference[1] describes how you can parse the value out of the header.

Thanks,
Andy

[1] - https://docs.oracle.com/javaee/6/tutorial/doc/glraq.html

-- 
Andrew Block

On September 2, 2015 at 7:01:42 AM, s.marjanovic (slavisa.marjanovic.83@gmail.com) wrote:

Hello,  

I'm creating a route that is supposed the accept an HTTP POST with a file  
and, among other things, archive that file. My route is as shown below:  

from("jetty:http://{{host}}?httpMethodRestrict=POST").routeId("MyRoute")  
.to("file:"+"{{localArchiveFile}}")  
.unmarshal().zipFile()  
.convertBodyTo(String.class)  
.inOnly("amq:queue:MyQueue?timeToLive={{timetolive}}");  

Stream cache is enabled on camel context level.  

The problem I have is that file gets archived as something like ".134216472"  
(a dot plus current system time).  

Here's the filename pattern for inspection:  
/data/archive/?fileName=${date:now:yyyyMMdd}/${file:onlyname}.${date:now:HHmmssSSS}  

I'd like to avoid this and save the file with it's original name with  
appended timestamp. I have inspected the exchange in debugger but I don't  
see the filename in in.headers or in.request. Is there a way that I'm  
missing that would enable me to get to the filename?  

Kind regards,  
Slavisa Marjanovic  






--  
View this message in context: http://camel.465427.n5.nabble.com/How-to-get-the-file-name-from-an-http-post-submitted-to-jetty-endpoint-tp5771156.html  
Sent from the Camel - Users mailing list archive at Nabble.com.