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 "Mudnal, Fayaz K" <fm...@visa.com> on 2010/10/27 19:59:14 UTC

Partial file uploaded

Hello

I'm using HttpClient 3.0 and am trying to upload a file using a Post method with MultipartRequestEntity. But only partial file is uploaded. The file is a .zip file. The file size is pretty small < 2MB.
When I upload anything over 1MB, only 280kb is transferred. But <750kb files get uploaded completely. I'm not sure what's going on here. Am I missing something in the headers or is the request not being built correctly??

Here is the code:

        PostMethod method = null;
        Header ua = new Header("User-Agent","Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0");
        method = new PostMethod(URL);
            method.setRequestHeader(ua);

        String filename= "TEST_FILE_2.ZIP";
            FilePart filePart = new FilePart("File", fileName, new File(filename));
            Part[] parts = new Part[1];
            parts[0] = filePart;

            HttpMethodParams methParams = method.getParams();
            methParams.setParameter("name","File");
            methParams.setParameter("filename",fileName);
            MultipartRequestEntity multi = new MultipartRequestEntity(parts, methParams);
            method.setRequestEntity(multi);

            method.setRequestHeader("filename", fileName);
            method.setRequestHeader("Content-Disposition", "form-data; name=\"File\"; filename=\"" + fileName + "\"");
        method.setRequestHeader("Content-Type", "multipart/form-data");

        method.setDoAuthentication(true);
            method.setFollowRedirects( false );
            HttpParams params = method.getParams();
            params.setParameter(CredentialsProvider.PROVIDER, new MyCredentialsProvider(username, password));
            int responseStatusCode = client.executeMethod(hostConfig, method);

Fayaz