You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Daniel Walsh <da...@verizon.net> on 2003/02/26 04:04:18 UTC
SocketException While Uploading Large File With MultipartPostMethod
As I mentioned in a previous posting (Subject: MultipartPostMethod Holding File Stream Open?), I'm using the MultipartPostMethod to upload a file to a servlet. Here is the example code that I included in the other posting:
> File file = new File(strUrl);
>
> HttpClient client = new HttpClient();
> HostConfiguration hostConfig = new HostConfiguration();
> MultipartPostMethod mpPost = new MultipartPostMethod();
>
> hostConfig.setHost(someURL.getHost(), someURL.getPort(),
> someURL.getProtocol());
> client.setConnectionTimeout(30000);
> client.setHostConfiguration(hostConfig);
>
> mpPost.addParameter("someName", "someValue");
> mpPost.addParameter(file.getName(), file);
>
> mpPost.setPath(strPath);
> client.executeMethod(mpPost);
>
> String confirmUpload = tpPost.getResponseBodyAsString();
> mpPost.releaseConnection();
I've been uploading some small text files (about 14KB each) and it seems to work properly in this situation. However, when I try to do the same with a 20MB file (I realize that this is a very large file, however, I want to test it's performance) a SocketException is thrown.
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:126)
at org.apache.commons.httpclient.methods.multipart.FilePart.sendData(FilePart.java:198)
at org.apache.commons.httpclient.methods.multipart.Part.send(Part.java:197)
at org.apache.commons.httpclient.methods.MultipartPostMethod.writeRequestBody(MultipartPostMethod.java:203)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1974)
at org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMethodBase.java:2298)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:915)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:557)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:474)
at test.FileUploader.upload(FileUploader.java:179)
at test.FileUploader.main(FileUploader.java:341)
Is there some kind of cap on the file size that I can send? If so, at what size is the cap set?
Re: SocketException While Uploading Large File With MultipartPostMethod
Posted by Ortwin Glück <or...@nose.ch>.
Daniel,
make sure you use a POST request that has the Content-Length header set.
Using chunked transfer encoding is not encouraged since most servers
will most reasonably limit the size of an unknown size upload due to the
possibility of DoS attacks.
Odi
Daniel Walsh wrote:
> Ok, 300MB is a pretty big file. So, I guess my 20MB shouldn't be creating a
> problem on this end. I'm posting to a servlet running on the Sun ONE
> application server, but I don't have that source code (the servlet) here
> with me. I'll have to find out tomorrow if he put a cap on the file size on
> that end, and then maybe check out the Sun ONE app server docs.
>
> If an error was being generated from the server side though, wouldn't I be
> getting my stack trace in the response body of my MultipartPostMethod?
>
> Daniel
Re: SocketException While Uploading Large File With MultipartPostMethod
Posted by Michael Becke <be...@u.washington.edu>.
>
> If an error was being generated from the server side though, wouldn't
> I be
> getting my stack trace in the response body of my MultipartPostMethod?
It is difficult to be sure. My guess is that the server closed the
socket while you were still writing.
Mike
Re: SocketException While Uploading Large File With MultipartPostMethod
Posted by Daniel Walsh <da...@verizon.net>.
> There is no real limit on the file size. I've done it with a 300MB
> file with no problem. The error could be on the server side. Any idea
> what is happening there? What are you posting to?
>
> Mike
Ok, 300MB is a pretty big file. So, I guess my 20MB shouldn't be creating a
problem on this end. I'm posting to a servlet running on the Sun ONE
application server, but I don't have that source code (the servlet) here
with me. I'll have to find out tomorrow if he put a cap on the file size on
that end, and then maybe check out the Sun ONE app server docs.
If an error was being generated from the server side though, wouldn't I be
getting my stack trace in the response body of my MultipartPostMethod?
Daniel
Re: SocketException While Uploading Large File With MultipartPostMethod
Posted by Michael Becke <be...@u.washington.edu>.
There is no real limit on the file size. I've done it with a 300MB
file with no problem. The error could be on the server side. Any idea
what is happening there? What are you posting to?
Mike
On Tuesday, February 25, 2003, at 10:04 PM, Daniel Walsh wrote:
> As I mentioned in a previous posting (Subject: MultipartPostMethod
> Holding File Stream Open?), I'm using the MultipartPostMethod to
> upload a file to a servlet. Here is the example code that I included
> in the other posting:
>
>> File file = new File(strUrl);
>>
>> HttpClient client = new HttpClient();
>> HostConfiguration hostConfig = new HostConfiguration();
>> MultipartPostMethod mpPost = new MultipartPostMethod();
>>
>> hostConfig.setHost(someURL.getHost(), someURL.getPort(),
>> someURL.getProtocol());
>> client.setConnectionTimeout(30000);
>> client.setHostConfiguration(hostConfig);
>>
>> mpPost.addParameter("someName", "someValue");
>> mpPost.addParameter(file.getName(), file);
>>
>> mpPost.setPath(strPath);
>> client.executeMethod(mpPost);
>>
>> String confirmUpload = tpPost.getResponseBodyAsString();
>> mpPost.releaseConnection();
>
> I've been uploading some small text files (about 14KB each) and it
> seems to work properly in this situation. However, when I try to do
> the same with a 20MB file (I realize that this is a very large file,
> however, I want to test it's performance) a SocketException is thrown.
>
> java.net.SocketException: Software caused connection abort: socket
> write error
> at java.net.SocketOutputStream.socketWrite0(Native Method)
> at
> java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
> at
> java.net.SocketOutputStream.write(SocketOutputStream.java:126)
> at
> org.apache.commons.httpclient.methods.multipart.FilePart.sendData(FileP
> art.java:198)
> at
> org.apache.commons.httpclient.methods.multipart.Part.send(Part.java:197
> )
> at
> org.apache.commons.httpclient.methods.MultipartPostMethod.writeRequestB
> ody(MultipartPostMethod.java:203)
> at
> org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBas
> e.java:1974)
> at
> org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMethodB
> ase.java:2298)
> at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.jav
> a:915)
> at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:
> 557)
> at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:
> 474)
> at test.FileUploader.upload(FileUploader.java:179)
> at test.FileUploader.main(FileUploader.java:341)
>
> Is there some kind of cap on the file size that I can send? If so, at
> what size is the cap set?
>