Hi,
I have a Tcl script on my server that I use to download multiple files from server with the help of Tcl. Everything works fine, except that the progress bar on the client machine is not working.
The Tcl script on the server (SoftwareDownload.cgi) builds the content that needs to be downloaded from the file contents and attaches the Content-Length information. Content-Lenght is also used by the client machine in order to display the progress bar:
set bound "-----NEXT_PART_[clock seconds].[pid]"
# Create content to be uploaded (path, EMail, Password, mtime, file content)
set content ""
set bytesize 0
foreach path $files relpath $relfiles {
# Get modified date of file
set mtime [file mtime $path]
# Get file size
incr bytesize [file size $path]
# Get file content of online path
set fid [open $path "rb"]
fconfigure $fid -encoding "binary" -translation "binary"
set data [read $fid]
close $fid
append content "--$bound\r\nContent-Disposition: form-data; name=\"path\"\r\n\r\n$relpath\r\n"
append content "--$bound\r\nContent-Disposition: form-data; name=\"mtime\"\r\n\r\n$mtime\r\n"
append content "--$bound\r\nContent-Disposition: form-data; name=\"data\"; filename=\"$path\"\r\n"
append content "--$bound\r\nContent-Type: application/octet-stream\r\n"
append content "--$bound\r\nContent-Transfer-Encoding: binary\r\n\r\n$data\r\n"
}
append content "--$bound--\r\n"
# Append info to activity.dat
Activity [file join $users_path $EMail] "Software download $relfiles"
fconfigure stdout -encoding "binary" -translation "binary"
puts "Content-Type: multipart/form-data; boundary=$bound"
puts "Content-Length: $bytesize"
puts "Content-Transfer-Encoding: Binary\r\n"
puts -nonewline $content
On the client machine I call something like:
::http::geturl
https://www.something.de/cgi-bin/SoftwareDownload.cgi -query paths=<filename>&dates=%7B%7D&EMail=<Email>&Password=<password> -headers {Accept-Encoding gzip} -progress ::meshparts::UIProgressBar
Although I specify the -progress option, the progress bar call back procedure gets as expected file size argument zero:
proc ::meshparts::UIProgressBar {token expected received} {
puts "$token $expected $received"
if {$expected==0} {
return
}
set ::meshparts::progress [expr {int(100.0 * double($received)/double($expected))}]
update idletasks
}
The Output of the callback is something like:
::http::178 0 8106
::http::178 0 16202
::http::178 0 24298
::http::178 0 32394
::http::178 0 40490
::http::178 0 48586
::http::178 0 56682
::http::178 0 64778
::http::178 0 72874
::http::178 0 80970
::http::178 0 89066
So obviously the content length is not intepreted correctly. I wonder what I'm doing wrong? Is my HTTP response header wrong?
Thanks!
Alexandru