hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: MultipartPostMethod adn UTF-8 parameter content.
Date Tue, 09 Nov 2004 18:41:56 GMT
Apparently the server does not decode the file names automatically (as
it should). Do you also control the server side script? If so, why do
not you simply use QCodec to decode the file name on the server side?

If not, your only resort is to provide a custom Part implementation that
is less picky about standards compliance

Oleg

On Tue, 2004-11-09 at 11:59, reudeml04@free.fr wrote:
> I have followed your advice and use the org.apache.commons.codec.net.QCodec
> package to encode the filename before sending the file. This code is :
> 
> QCodec qc = new QCodec();
> mPost.addParameter("upload_file",qc.encode(f1.getName(),"UTF-8"),f1);
> 
> but it does not solve the problem as now the receiving server does NOT interpret
> the encoding.
> A dump of the wire shows :
> 
> DEBUG [org.apache.commons.httpclient.methods.MultipartPostMethod] enter
> MultipartPostMethod.writeRequestBody(HttpState state, HttpConnection conn)
> DEBUG [org.apache.commons.httpclient.HttpConnection] enter
> HttpConnection.getRequestOutputStream()
> DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
> sendParts(OutputStream out, Parts[])
> DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
> send(OutputStream out)
> DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
> sendStart(OutputStream out)
> DEBUG [httpclient.wire] >> "--"
> DEBUG [httpclient.wire] >> "----------------314159265358979323846"
> DEBUG [httpclient.wire] >> "[\r][\n]"
> DEBUG [org.apache.commons.httpclient.methods.multipart.FilePart] enter
> sendDispositionHeader(OutputStream out)
> DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
> sendDispositionHeader(OutputStream out)
> DEBUG [httpclient.wire] >> "Content-Disposition: form-data; name="
> DEBUG [httpclient.wire] >> """
> DEBUG [httpclient.wire] >> "upload_file"
> DEBUG [httpclient.wire] >> """
> DEBUG [httpclient.wire] >> "; filename="
> DEBUG [httpclient.wire] >> """
> DEBUG [httpclient.wire] >>
> "=?UTF-8?Q?note=C2=AF=C2=AFtraining=C2=AF24103-04.doc?="
> DEBUG [httpclient.wire] >> """
> 
> Any idea ?
> 
> 
> 
> Quoting Guillaume Cottenceau <gc@mnc.ch>:
> 
> > reudeml04 'at' free.fr writes:
> >
> > > Hi All,
> > >
> > > I am using HTTPClient 3.0a2 and I am trying to mimic the POST of a form to
> > > upload a binary file.
> > > The code I use is below:
> > >
> > > MultipartPostMethod mPost = new MultipartPostMethod(addFileToPackageURL);
> > > File f1 = new File(fa.getFilePath() + "\\" + fa.getFileName());
> > > mPost.addParameter("upload_file",f1.getName(),f1);
> > >
> > > It works fine for all files BUT when the filename contains non basic ASCII
> > chars
> > > (like UTF-8), the received filename is transformed and unknow chars are
> > changed
> > > to question marks ?.
> > >
> > > It tried to add  mPost.addRequestHeader("Content-Type", "charset=\"UTF-8\""
> > );
> > > but it does not change anything.
> > >
> > > How should I proceed to allow the submit of a filename like
> > > "note¯¯training¯abc.doc" so that it does not become
> > > "note??training?abc.doc" on the other end of the wire ?
> > >
> > > Is this a bug or am I doing something wrong (likely :-)) ?
> > >
> > > Any help or suggestion would be much appreciated.
> >
> > It seems that javadoc explains that.
> >
> >
> http://jakarta.apache.org/commons/httpclient/3.0/apidocs/org/apache/commons/httpclient/methods/MultipartPostMethod.html
> >
> > "Field names originally in non-ASCII character sets may be
> > encoded using the method outlined in RFC 1522."
> >
> > --
> > Guillaume Cottenceau
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 


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


Mime
View raw message