You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Emilian Utma <ut...@gmail.com> on 2012/05/21 14:55:18 UTC

HttpClient API - upload files using OutputStream not Filepart

Hello,

I want to know if is possible to upload a file which its content is set via
a java.io.OutputStream (as in "old times" when using
java.net.HttpURLConnection) not
org.apache.commons.httpclient.methods.multipart.FilePart.Filepart.

I need this behaviour because the content is provided by another
application not mine. To save the content in a "temp" zone is not an option
because it is possible to receive hundreds of files per seconds ... and
this will require a "big temp".

Thank you in advance.

Best regards,
Emil

Re: HttpClient API - upload files using OutputStream not Filepart

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, May 22, 2012 at 10:24:07AM +0300, Emilian Utma wrote:
> Hello Oleg,
> 
> Thank you for your reply.
> 
> I'll try to implement a "homemade" httpclient based on the Apache HttpCore
> component.
> 
> Best regards,
> Emil
> 

Let me know if you need help with the API.

Oleg


> On Mon, May 21, 2012 at 6:48 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > On Mon, 2012-05-21 at 17:13 +0300, Emilian Utma wrote:
> > > Hello,
> > >
> > > Thank you for your quick reply.
> > >
> > > This is indeed a solution but I'm afraid it won't solve my problem
> > (sorry,
> > > I wasn't very specific in my issue). Unfortunately I don't have access to
> > > the inputStream, I can only expose the outputstream (as a
> > > WritableByteChannel) to the other application because the writing is
> > > provided by it. If I use the HttpEntity interface then I have to modify
> > > that application to implement HttpEntity ... which is not possible ...
> > >
> > > Thank you anyway.
> > >
> > > Best regards,
> > > Emil
> > >
> >
> > Emil
> >
> > It is a conscious design decision to not expose the underling socket and
> > its input and output streams to HttpClient API consumers. This enables
> > HttpClient to ensure that persistent connections are always in a
> > consistent state when kept alive. You still have an option of dropping
> > to HttpCore and implementing your own HTTP connection API while still
> > re-using framework's transport and connection pooling capabilities.
> >
> > Oleg
> >
> >
> > > P.S. I'm trying to implement a some kind of "HttpContentWriter" module
> > in a
> > > ECM framework where all the content of documents (e.g. files) will be
> > > uploaded on a storage device using HTTP protocol.
> > >
> > > On Mon, May 21, 2012 at 4:12 PM, Mark Claassen <ma...@donnell.com>
> > wrote:
> > >
> > > > It is pretty easy to make your own HttpEntity.  There are just a few
> > > > methods.  You can just implement this interface to wrap
> > > > whatever object you are dealing with.  Then in the writeTo method, you
> > can
> > > > read from your stream and write it out right away.
> > > >
> > > > -----Original Message-----
> > > > From: Emilian Utma [mailto:utma.emilian@gmail.com]
> > > > Sent: Monday, May 21, 2012 8:55 AM
> > > > To: httpclient-users@hc.apache.org
> > > > Subject: HttpClient API - upload files using OutputStream not Filepart
> > > >
> > > > Hello,
> > > >
> > > > I want to know if is possible to upload a file which its content is set
> > > > via a java.io.OutputStream (as in "old times" when using
> > > > java.net.HttpURLConnection) not
> > > > org.apache.commons.httpclient.methods.multipart.FilePart.Filepart.
> > > >
> > > > I need this behaviour because the content is provided by another
> > > > application not mine. To save the content in a "temp" zone is not
> > > > an option because it is possible to receive hundreds of files per
> > seconds
> > > > ... and this will require a "big temp".
> > > >
> > > > Thank you in advance.
> > > >
> > > > Best regards,
> > > > Emil
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > > >
> > > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: HttpClient API - upload files using OutputStream not Filepart

Posted by Emilian Utma <ut...@gmail.com>.
Hello Oleg,

Thank you for your reply.

I'll try to implement a "homemade" httpclient based on the Apache HttpCore
component.

Best regards,
Emil

On Mon, May 21, 2012 at 6:48 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Mon, 2012-05-21 at 17:13 +0300, Emilian Utma wrote:
> > Hello,
> >
> > Thank you for your quick reply.
> >
> > This is indeed a solution but I'm afraid it won't solve my problem
> (sorry,
> > I wasn't very specific in my issue). Unfortunately I don't have access to
> > the inputStream, I can only expose the outputstream (as a
> > WritableByteChannel) to the other application because the writing is
> > provided by it. If I use the HttpEntity interface then I have to modify
> > that application to implement HttpEntity ... which is not possible ...
> >
> > Thank you anyway.
> >
> > Best regards,
> > Emil
> >
>
> Emil
>
> It is a conscious design decision to not expose the underling socket and
> its input and output streams to HttpClient API consumers. This enables
> HttpClient to ensure that persistent connections are always in a
> consistent state when kept alive. You still have an option of dropping
> to HttpCore and implementing your own HTTP connection API while still
> re-using framework's transport and connection pooling capabilities.
>
> Oleg
>
>
> > P.S. I'm trying to implement a some kind of "HttpContentWriter" module
> in a
> > ECM framework where all the content of documents (e.g. files) will be
> > uploaded on a storage device using HTTP protocol.
> >
> > On Mon, May 21, 2012 at 4:12 PM, Mark Claassen <ma...@donnell.com>
> wrote:
> >
> > > It is pretty easy to make your own HttpEntity.  There are just a few
> > > methods.  You can just implement this interface to wrap
> > > whatever object you are dealing with.  Then in the writeTo method, you
> can
> > > read from your stream and write it out right away.
> > >
> > > -----Original Message-----
> > > From: Emilian Utma [mailto:utma.emilian@gmail.com]
> > > Sent: Monday, May 21, 2012 8:55 AM
> > > To: httpclient-users@hc.apache.org
> > > Subject: HttpClient API - upload files using OutputStream not Filepart
> > >
> > > Hello,
> > >
> > > I want to know if is possible to upload a file which its content is set
> > > via a java.io.OutputStream (as in "old times" when using
> > > java.net.HttpURLConnection) not
> > > org.apache.commons.httpclient.methods.multipart.FilePart.Filepart.
> > >
> > > I need this behaviour because the content is provided by another
> > > application not mine. To save the content in a "temp" zone is not
> > > an option because it is possible to receive hundreds of files per
> seconds
> > > ... and this will require a "big temp".
> > >
> > > Thank you in advance.
> > >
> > > Best regards,
> > > Emil
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > >
> > >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: HttpClient API - upload files using OutputStream not Filepart

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2012-05-21 at 17:13 +0300, Emilian Utma wrote:
> Hello,
> 
> Thank you for your quick reply.
> 
> This is indeed a solution but I'm afraid it won't solve my problem (sorry,
> I wasn't very specific in my issue). Unfortunately I don't have access to
> the inputStream, I can only expose the outputstream (as a
> WritableByteChannel) to the other application because the writing is
> provided by it. If I use the HttpEntity interface then I have to modify
> that application to implement HttpEntity ... which is not possible ...
> 
> Thank you anyway.
> 
> Best regards,
> Emil
> 

Emil

It is a conscious design decision to not expose the underling socket and
its input and output streams to HttpClient API consumers. This enables
HttpClient to ensure that persistent connections are always in a
consistent state when kept alive. You still have an option of dropping
to HttpCore and implementing your own HTTP connection API while still
re-using framework's transport and connection pooling capabilities.

Oleg 


> P.S. I'm trying to implement a some kind of "HttpContentWriter" module in a
> ECM framework where all the content of documents (e.g. files) will be
> uploaded on a storage device using HTTP protocol.
> 
> On Mon, May 21, 2012 at 4:12 PM, Mark Claassen <ma...@donnell.com> wrote:
> 
> > It is pretty easy to make your own HttpEntity.  There are just a few
> > methods.  You can just implement this interface to wrap
> > whatever object you are dealing with.  Then in the writeTo method, you can
> > read from your stream and write it out right away.
> >
> > -----Original Message-----
> > From: Emilian Utma [mailto:utma.emilian@gmail.com]
> > Sent: Monday, May 21, 2012 8:55 AM
> > To: httpclient-users@hc.apache.org
> > Subject: HttpClient API - upload files using OutputStream not Filepart
> >
> > Hello,
> >
> > I want to know if is possible to upload a file which its content is set
> > via a java.io.OutputStream (as in "old times" when using
> > java.net.HttpURLConnection) not
> > org.apache.commons.httpclient.methods.multipart.FilePart.Filepart.
> >
> > I need this behaviour because the content is provided by another
> > application not mine. To save the content in a "temp" zone is not
> > an option because it is possible to receive hundreds of files per seconds
> > ... and this will require a "big temp".
> >
> > Thank you in advance.
> >
> > Best regards,
> > Emil
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: HttpClient API - upload files using OutputStream not Filepart

Posted by Emilian Utma <ut...@gmail.com>.
Hello,

Thank you for your quick reply.

This is indeed a solution but I'm afraid it won't solve my problem (sorry,
I wasn't very specific in my issue). Unfortunately I don't have access to
the inputStream, I can only expose the outputstream (as a
WritableByteChannel) to the other application because the writing is
provided by it. If I use the HttpEntity interface then I have to modify
that application to implement HttpEntity ... which is not possible ...

Thank you anyway.

Best regards,
Emil

P.S. I'm trying to implement a some kind of "HttpContentWriter" module in a
ECM framework where all the content of documents (e.g. files) will be
uploaded on a storage device using HTTP protocol.

On Mon, May 21, 2012 at 4:12 PM, Mark Claassen <ma...@donnell.com> wrote:

> It is pretty easy to make your own HttpEntity.  There are just a few
> methods.  You can just implement this interface to wrap
> whatever object you are dealing with.  Then in the writeTo method, you can
> read from your stream and write it out right away.
>
> -----Original Message-----
> From: Emilian Utma [mailto:utma.emilian@gmail.com]
> Sent: Monday, May 21, 2012 8:55 AM
> To: httpclient-users@hc.apache.org
> Subject: HttpClient API - upload files using OutputStream not Filepart
>
> Hello,
>
> I want to know if is possible to upload a file which its content is set
> via a java.io.OutputStream (as in "old times" when using
> java.net.HttpURLConnection) not
> org.apache.commons.httpclient.methods.multipart.FilePart.Filepart.
>
> I need this behaviour because the content is provided by another
> application not mine. To save the content in a "temp" zone is not
> an option because it is possible to receive hundreds of files per seconds
> ... and this will require a "big temp".
>
> Thank you in advance.
>
> Best regards,
> Emil
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

RE: HttpClient API - upload files using OutputStream not Filepart

Posted by Mark Claassen <ma...@donnell.com>.
It is pretty easy to make your own HttpEntity.  There are just a few methods.  You can just implement this interface to wrap
whatever object you are dealing with.  Then in the writeTo method, you can read from your stream and write it out right away.

-----Original Message-----
From: Emilian Utma [mailto:utma.emilian@gmail.com] 
Sent: Monday, May 21, 2012 8:55 AM
To: httpclient-users@hc.apache.org
Subject: HttpClient API - upload files using OutputStream not Filepart

Hello,

I want to know if is possible to upload a file which its content is set via a java.io.OutputStream (as in "old times" when using
java.net.HttpURLConnection) not
org.apache.commons.httpclient.methods.multipart.FilePart.Filepart.

I need this behaviour because the content is provided by another application not mine. To save the content in a "temp" zone is not
an option because it is possible to receive hundreds of files per seconds ... and this will require a "big temp".

Thank you in advance.

Best regards,
Emil


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org