Hi All,
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
set fd [open my_file.xlsx w]
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
Manfred
Hi All,
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
set fd [open my_file.xlsx w]
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
Manfred Schwarz <[email protected]> wrote:
Hi All,
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]Without showing us the HTTP headers that the Rivet server is providing
set data [http::data $token]
http::cleanup $token
here, we are very limited in being able to provide any troubleshooting
help.
set fd [open my_file.xlsx w]
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?Most commonly, it is because the http headers are indicating the file
is text, when they should be indicating that it is a binary file.
Rich schrieb am Montag, 28. November 2022 um 16:27:58 UTC+1:
Manfred Schwarz <[email protected]> wrote:
Hi All,Without showing us the HTTP headers that the Rivet server is providing
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
here, we are very limited in being able to provide any troubleshooting
help.
set fd [open my_file.xlsx w]Most commonly, it is because the http headers are indicating the file
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
is text, when they should be indicating that it is a binary file.
Hi Rich,
thank you for your answer!
Following are some informations about the url on client side:
Connection = close
Content-Type = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date = Mon, 28 Nov 2022 1
GMT
Server = Apache/2.4.54 (Unix) OpenSSL/1.1.1l Rivet Transfer-Encoding = chunked
% eval puts $$token\(status)
ok
% eval puts $$token\(charset)
iso8859-1
% eval puts $$token\(binary)
1
set fd [open my_file.xlsx {RDONLY BINARY}]
puts [read -nonewline $fd]
close $fd
Manfred Schwarz <[email protected]> wrote:
Rich schrieb am Montag, 28. November 2022 um 16:27:58 UTC+1:
Manfred Schwarz <[email protected]> wrote:
Hi All,Without showing us the HTTP headers that the Rivet server is providing
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
here, we are very limited in being able to provide any troubleshooting
help.
set fd [open my_file.xlsx w]Most commonly, it is because the http headers are indicating the file
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
is text, when they should be indicating that it is a binary file.
Hi Rich,
thank you for your answer!
Following are some informations about the url on client side:
Connection = close
Content-Type = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date = Mon, 28 Nov 2022 1
GMT
Server = Apache/2.4.54 (Unix) OpenSSL/1.1.1l Rivet
Transfer-Encoding = chunked
% eval puts $$token\(status)Hmm, binary mode was auto-enabled by the http module, so Tcl's http
ok
% eval puts $$token\(charset)
iso8859-1
% eval puts $$token\(binary)
1
should be downloading it correctly. If you save the data into a file
opened in binary mode, does a hash of that file match a hash of the
original on the server?
Can you also make updates to the rivet script? If yes, try this:
Does that make any difference?set fd [open my_file.xlsx {RDONLY BINARY}]
puts [read -nonewline $fd]
close $fd
Rich schrieb am Montag, 28. November 2022 um 17:51:02 UTC+1:
Manfred Schwarz <[email protected]> wrote:
Rich schrieb am Montag, 28. November 2022 um 16:27:58 UTC+1:Hmm, binary mode was auto-enabled by the http module, so Tcl's http
Manfred Schwarz <[email protected]> wrote:
Hi All,Without showing us the HTTP headers that the Rivet server is providing
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
here, we are very limited in being able to provide any troubleshooting
help.
set fd [open my_file.xlsx w]Most commonly, it is because the http headers are indicating the file
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
is text, when they should be indicating that it is a binary file.
Hi Rich,
thank you for your answer!
Following are some informations about the url on client side:
Connection = close
Content-Type = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date = Mon, 28 Nov 2022 1
GMT
Server = Apache/2.4.54 (Unix) OpenSSL/1.1.1l Rivet
Transfer-Encoding = chunked
% eval puts $$token\(status)
ok
% eval puts $$token\(charset)
iso8859-1
% eval puts $$token\(binary)
1
should be downloading it correctly. If you save the data into a file
opened in binary mode, does a hash of that file match a hash of the
original on the server?
Can you also make updates to the rivet script? If yes, try this:
Does that make any difference?set fd [open my_file.xlsx {RDONLY BINARY}]
puts [read -nonewline $fd]
close $fd
The hash values are different (server: 5DE2182EF5455D69F8BDA31CD70F6D94 client: 02444C78C123647D4FE27A3ED0995C11).
The change in opening the output file doesn't make any difference
puts [read -nonewline $fd]
Manfred Schwarz <[email protected]> wrote:
Rich schrieb am Montag, 28. November 2022 um 17:51:02 UTC+1:
Manfred Schwarz <[email protected]> wrote:
Rich schrieb am Montag, 28. November 2022 um 16:27:58 UTC+1:Hmm, binary mode was auto-enabled by the http module, so Tcl's http
Manfred Schwarz <[email protected]> wrote:
Hi All,Without showing us the HTTP headers that the Rivet server is providing >> >> here, we are very limited in being able to provide any troubleshooting >> >> help.
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
set fd [open my_file.xlsx w]Most commonly, it is because the http headers are indicating the file >> >> is text, when they should be indicating that it is a binary file.
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
Hi Rich,
thank you for your answer!
Following are some informations about the url on client side:
Connection = close
Content-Type = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date = Mon, 28 Nov 2022 1
GMT
Server = Apache/2.4.54 (Unix) OpenSSL/1.1.1l Rivet
Transfer-Encoding = chunked
% eval puts $$token\(status)
ok
% eval puts $$token\(charset)
iso8859-1
% eval puts $$token\(binary)
1
should be downloading it correctly. If you save the data into a file
opened in binary mode, does a hash of that file match a hash of the
original on the server?
Can you also make updates to the rivet script? If yes, try this:
Does that make any difference?set fd [open my_file.xlsx {RDONLY BINARY}]
puts [read -nonewline $fd]
close $fd
The hash values are different (server: 5DE2182EF5455D69F8BDA31CD70F6D94 client: 02444C78C123647D4FE27A3ED0995C11).
The change in opening the output file doesn't make any differenceHmm, just noticed this one, change this:
puts [read -nonewline $fd]
to this
puts -nonewline [read $fd]
You want all of the bytes read to go into the file, and you do not want
puts adding a newline of its own automatically.
The prior version is changing the file enough to make the hashes
differ.
Rich schrieb am Montag, 28. November 2022 um 18:56:27 UTC+1:
Manfred Schwarz <[email protected]> wrote:
Rich schrieb am Montag, 28. November 2022 um 17:51:02 UTC+1:
Manfred Schwarz <[email protected]> wrote:
Rich schrieb am Montag, 28. November 2022 um 16:27:58 UTC+1:Hmm, binary mode was auto-enabled by the http module, so Tcl's http
Manfred Schwarz <[email protected]> wrote:
Hi All,Without showing us the HTTP headers that the Rivet server is providing
in my client-server application, the client needs to retrieve some binary files (e.g. Office files, images, etc.) from the server.
When the file is stored on the client, the corresponding application (e.g. Excel) cannot open the file because the file format is wrong.
The transferred file is larger than the original.
If I transfer the file directly (http::geturl http://<server_ip>/my_file.xlsx) or with WinScp, it is fine.
Client-Side:
...
package require http
set token [http::geturl "http://<server_ip>/get_my_file.rvt"]
set data [http::data $token]
http::cleanup $token
here, we are very limited in being able to provide any troubleshooting
help.
set fd [open my_file.xlsx w]Most commonly, it is because the http headers are indicating the file >> >> is text, when they should be indicating that it is a binary file.
fconfigure $fd -translation binary
puts -nonewline $fd $data
close $fd
...
Rivet-Script:
<?
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
set fd [open my_file.xlsx r]
fconfigure $fd -translation binary
puts [read -nonewline $fd]
close $fd
Do you have any idea what is the reason for this?
Hi Rich,
thank you for your answer!
Following are some informations about the url on client side:
Connection = close
Content-Type = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date = Mon, 28 Nov 2022 1
GMT
Server = Apache/2.4.54 (Unix) OpenSSL/1.1.1l Rivet
Transfer-Encoding = chunked
% eval puts $$token\(status)
ok
% eval puts $$token\(charset)
iso8859-1
% eval puts $$token\(binary)
1
should be downloading it correctly. If you save the data into a file
opened in binary mode, does a hash of that file match a hash of the
original on the server?
Can you also make updates to the rivet script? If yes, try this:
Does that make any difference?set fd [open my_file.xlsx {RDONLY BINARY}]
puts [read -nonewline $fd]
close $fd
The hash values are different (server: 5DE2182EF5455D69F8BDA31CD70F6D94 client: 02444C78C123647D4FE27A3ED0995C11).
The change in opening the output file doesn't make any differenceHmm, just noticed this one, change this:
puts [read -nonewline $fd]
to this
puts -nonewline [read $fd]
You want all of the bytes read to go into the file, and you do not want puts adding a newline of its own automatically.
The prior version is changing the file enough to make the hashesHi Rich,
differ.
I have changed this. The hash is another, but not the same as the original.
Manfred
* Manfred Schwarz <[email protected]>
| Today I tried this on the server, and it works:
| <?
| catch {unset data}
| set fd [open test.xlsx r]
| fconfigure $fd -translation binary
| set data [read $fd]
| close $fd
| ::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
| ::rivet::headers add Content-Length [string length $data]
| set origEncoding [encoding system]
| fconfigure stdout -encoding iso8859-1
| puts -nonewline "$data"
| fconfigure stdout -encoding $origEncoding
| ?>
I have a strong feeling against reading the data as binary and then
sending them as iso8859. It sounds to me like a data dependent bug
waiting to happen. As long as the data are all-ASCII, there should be
no problem, but as soon as you encounter non-ASCII... *possible boom*.
The data on disk have a specific encoding (which?), and so it seems best
to me to read them in that encoding.
Then indicate in the transfer-headers which encoding is used to send the data, and send them in that encoding.
My EUR 0.01
R'
Manfred Schwarz schrieb am Dienstag, 29. November 2022 um 09:00:18 UTC+1:
I think I have the solution.
Today I tried this on the server, and it works:
<?
catch {unset data}
set fd [open test.xlsx r]
fconfigure $fd -translation binary
set data [read $fd]
close $fd
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
::rivet::headers add Content-Length [string length $data]
set origEncoding [encoding system]
fconfigure stdout -encoding iso8859-1
puts -nonewline "$data"
fconfigure stdout -encoding $origEncoding
Then I found out that the new server uses the UTF-8 character set
instead of the ISO-8859-1 like the old server.
So I just have to change the charset of the new server and it should work.
Manfred Schwarz <[email protected]> wrote:
Manfred Schwarz schrieb am Dienstag, 29. November 2022 um 09:00:18 UTC+1:
I think I have the solution.
Today I tried this on the server, and it works:
<?
catch {unset data}
set fd [open test.xlsx r]
fconfigure $fd -translation binary
set data [read $fd]
close $fd
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
::rivet::headers add Content-Length [string length $data]
set origEncoding [encoding system]
fconfigure stdout -encoding iso8859-1
puts -nonewline "$data"
fconfigure stdout -encoding $origEncoding
Then I found out that the new server uses the UTF-8 character set
instead of the ISO-8859-1 like the old server.
So I just have to change the charset of the new server and it should work.Except, if the file is really an xlsx file (as opposed to just being
named xlsx) then it is a zip file in disguise, and is really a binary
file, so transmitting it over a channel set to UTF-8 will corrupt the
binary data as Tcl translates the contents into UTF-8 encoding.
But, your 'fix' reminded me that I did not pay attention to the fact
that you were using rivet's stdout to send the file data, without first configuring stdout. What you'll want, for an xlsx file, is this:
<?
# this unset here is unnecessary if you do "set data" below, which
# will 'delete' any old 'data' variable contents anyway.
catch {unset data}
set fd [open test.xlsx r]
# adding -encoding binary makes sure Tcl does not modify the data
# in any way (this is why I prefer the {RDONLY BINARY} method for
# [open], then there is no need to fconfigure the channel
fconfigure $fd -translation binary -encoding binary
set data [read $fd]
close $fd
::rivet::headers type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
::rivet::headers add Content-Length [string length $data]
# if you really want to reset things, you'll want to not do this
#set origEncoding [encoding system]
# and do this instead
set origConfig [fconfigure stdout]
fconfigure stdout -encoding binary -translation binary
puts -nonewline "$data"
fconfigure stdout -encoding [dict get $origConfig -encoding] -translation [dict get $origConfig -translation]
But, do note that this above only works for files that really are meant
to be sent as binary data. Files that are meant to be sent as text
will be 'hit-or-miss' with the above pattern.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 134:48:45 |
| Calls: | 12,087 |
| Files: | 14,997 |
| Messages: | 6,517,357 |