Hi Dean,
Dean Krueger wrote:
> Hi Roland,
> Thanks for your reply, I was wondering if you would you be able to
> elaborate
> a little more on this solution?
I'm not sure what other information you need? I'm not going to
write the code for you. Since you're posting a file and probably
don't care a lot about the extra data, it's probably the easiest
thing if you don't create your own RequestEntity, but your own
FilePart. Start with the FilePart in HttpClient and change the
method sendData(OutputStream). Whenever you write something to
the OutputStream, you count the number of bytes you have written.
A second thread can then poll the value in regular intervals to
display the progress.
If you want to track all the bytes being sent, you'll have to
re-implement a RequestEntity which creates a wrapper for the
OutputStream. Then you could count the bytes in that wrapper
for that stream.
hope that helps,
Roland
> This is my main method for sending the
> files:
>
> public int sendFile(String theFile){
> int result = -1;
>
> try {
> targetFile = new File(theFile);
>
> filePost = new PostMethod("
> http://localhost:8084/UploadServer/UploadServer.jsp");
>
> Part[] parts = {new FilePart(targetFile.getName(), targetFile)};
>
> filePost.setRequestEntity(new MultipartRequestEntity(parts,
> filePost.getParams()));
>
> HttpClient client = new HttpClient();
>
> client.getHttpConnectionManager
> ().getParams().setConnectionTimeout(5000);
>
> iStatus = client.executeMethod(filePost);
>
> if (iStatus == HttpStatus.SC_OK) {
> System.out.println("Upload complete, response=" +
> filePost.getResponseBodyAsString());
> } else {
> System.out.println("Upload failed, response=" +
> HttpStatus.getStatusText(iStatus));
> }
> } catch (java.net.ConnectException ex){
> iStatus = 22;
> ex.printStackTrace();
> }
> catch(IOException e2){;}
>
> finally {
> filePost.releaseConnection();
> }
>
> result = iStatus;
>
> return result;
> }
>
> This code works fine, however I have no way of knowing how many bytes
> have been transferred as I would like to have a progress bar showing the
> status.
>
> Any help is truly appreciated!
>
> Thanks
> Dean Krueger
>
>
> On 4/4/06, Roland Weber <[EMAIL PROTECTED]> wrote:
>
>>
>> Hello Dean,
>>
>> > Any thoughts on how I could track the upload, or do it another way?
>>
>> You have to implement your own RequestEntity to track the upload.
>> It can be a wrapper around the MultipartRequestEntity you're using.
>> You'll also find this discussed in the mailing list archives,
>> though I'm not sure whether on the user or developer list.
>>
>> hope that helps,
>> Roland
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]