Hi. It was long time ago, I don't remember anything.
But my uploader is open source, you can check
http://code.google.com/p/umpirsky-uploader/source/browse/#svn/trunk/src/umpirsky/umpirsky

Hope this helps.


metalheart2003 wrote:
> 
> Hi umpirsky, 
> Sorry, but I'm hard to run this code in my applet. 
> In
> 
> filePost.setRequestEntity(new UmpirskyRequestEntity(
> new MultipartRequestEntity(parts, filePost.getParams()),
> new UmpirskyProgressListener(this, (long)targetFile.length())));
> 
> in "this" I get the failure:
> 
> symbol  : constructor UmpirskyProgressListener(upload,long)
> location: class upload.UmpirskyProgressListener  new
> UmpirskyProgressListener(this, (long)targetFile.length())));
> Note: Some input files use unchecked or unsafe operations. 
> 
> 
> I spend all my code. 
> Thank you very much for your help!
> 
> ...
> import umpirsky.UmpirskyRequestEntity.ProgressListener;
> import umpirsky.UmpirskyUploader;
> import umpirsky.UmpirskyRequestEntity;
> import umpirsky.UmpirskyProgressListener;
> ...
> String targetURL =
> "http://localhost/swfupload/demos/swfobjectdemo/upload.aspx";;
> PostMethod filePost = new PostMethod(targetURL);
> filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,true);
> try {
>     File targetFile = new File("C:\\temp\\pruebas\\1_MOV01114.rar"); //
> FICHERO
> 
>     UploadFichero.consola("Uploading #" + targetFileString +  "# to " +
> targetURL);
>     Part[] parts = {new FilePart("file", targetFile)}; //PARAMETROS
> 
>     filePost.setRequestEntity(
>             new MultipartRequestEntity(parts,
>             filePost.getParams())
>             );
> 
>     HttpClient client = new HttpClient();
>    
> client.getHttpConnectionManager().getParams().setConnectionTimeout(50000);
> 
>     filePost.setRequestEntity(new UmpirskyRequestEntity(
>                                 new MultipartRequestEntity(parts,
> filePost.getParams()),
>                                 new UmpirskyProgressListener(this,
> (long)targetFile.length())));
> ...
> public class UmpirskyProgressListener extends Observable implements
> ProgressListener {
>        ...
>         public UmpirskyProgressListener(UmpirskyUploader observer, long
> bytesToSend) {
>                 // for some reson, twice much bytes is sent to server, so
> this is ugly patch
>                 this.bytesToSend = 2 * bytesToSend;
>                 this.addObserver(observer);
>         }
> ...
>         public void transferred(long bytes) {
>                 this.setChanged();
>                 System.out.println("progress="+((float)
> bytes/this.bytesToSend * 100));
>                 //this.notifyObservers();
>         }
> 
> }
> }
> 
> 
> 
> umpirsky wrote:
>> 
>> postMethod.setRequestEntity(new UmpirskyRequestEntity(new
>> MultipartRequestEntity(parts, postMethod.getParams()), new
>> UmpirskyProgressListener(this, bytesToSend)));
>> 
>> and in my case UmpirskyProgressListener :
>> 
>> 
>> package umpirsky;
>> 
>> import java.util.Observable;
>> 
>> import umpirsky.UmpirskyRequestEntity.ProgressListener;
>> 
>> public class UmpirskyProgressListener extends Observable implements
>> ProgressListener {
>>      /**
>>       * Number of bytes to send
>>       */
>>      private long bytesToSend;
>> 
>>      /**
>>       * Progress constructor
>>       *
>>       * @author Saša Stamenković <[email protected]>
>>       * @param UmpirskyUploader observer applet is observer. monitors upload
>> progress
>>       * @param long bytesToSend number of bytes that need to be sent
>>       */
>>      public UmpirskyProgressListener(UmpirskyUploader observer, long
>> bytesToSend) {
>>              // for some reson, twice much bytes is sent to server, so this 
>> is ugly
>> patch
>>              this.bytesToSend = 2 * bytesToSend;
>>              this.addObserver(observer);
>>      }
>> 
>>      /**
>>       * Triggered on every byte sent
>>       *
>>       * @author Saša Stamenković <[email protected]>
>>       * @param long bytes number of bytes sent
>>       * @return void
>>       */
>>      public void transferred(long bytes) {
>>              this.setChanged();
>>              this.notifyObservers((float) bytes/this.bytesToSend * 100);
>>      }
>> 
>> }
>> 
>> you can implement your own ProgressListener and do what is needed
>> there...in my case that is observable listener which notifies observer to
>> update GUI.
>> 
>> Hope this helps, if not don't be hesitate to ask ;)
>> 
>> 
>> 
>> soapergem wrote:
>>> 
>>> umpirsky,
>>> 
>>> Could you post a complete code example please? I am still not sure how
>>> to use this class. Thanks.
>>> 
>>> Regards,
>>> 
>>> Gordon
>>> 
>>> 
>>> umpirsky wrote:
>>>> 
>>>> Cool, it works!
>>>> 
>>>> Seems like number of bytes sent is about 2Xfile.lenght().
>>>> 
>>>> For file size 105542b it sends 211606b,
>>>> For file size 43062b it sends 86642b
>>>> 
>>>> any explanation???
>>>> 
>>>> 
>>>> Marcel Schiffel wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> it's wrapped around another request entity, for example:
>>>>> 
>>>>>           PostMethod method = new PostMethod(...);
>>>>>           FileRequestEntity fre = new FileRequestEntity(someFile,
>>>>> "contentType");
>>>>>           method.setRequestEntity(new CountingRequestEntity(fre, 
>>>>> listener));
>>>>> 
>>>>> I've been able to use it with only minor changes (changed the type of
>>>>> the listener to ProgressHandle of the Netbeans Progress API). It's
>>>>> successfully counting the bytes sent, but I'm still not able to
>>>>> determine the total number of bytes that are sent, before executing
>>>>> the request. I'm therefore unable to tell the status bar what number
>>>>> of bytes is equivalent to 100%. Furthermore it is still not clear how
>>>>> to achieve the same thing when downloading a file (evaluating the
>>>>> response body stream).
>>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p23451220.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to