1
votes

I have a HTTP server (newLISP running on a Linux box), which runs my CGI scripts. It runs on my Linux box.

I have a strange problem with uploading files using the POST method. My CGI script is simple: it reads everything from stdin, and saves it in a file. I wrote the script for debugging purposes: I wanted to know, what exactly is read.

When I upload a text file, everything is fine. I mean I get something like that:

-----------------------------18218802734725416881815749595
Content-Disposition: form-data; name="uploaded_data"; filename="post.gif"
Content-Type: image/gif

(and here's the content of the text file)

-----------------------------18218802734725416881815749595
Content-Disposition: form-data; name="text_field_name"

text field value
-----------------------------18218802734725416881815749595
Content-Disposition: form-data; name="submit"

Upload
-----------------------------18218802734725416881815749595--

And that's exactly what I should get, according to the RFC 1867 (Form-based File Upload in HTML). (Yes, I renamed this text file to "post.gif".)

The problem is, I get something really strange, when I try to upload any binary file. For example, when I upload a gif image, I get this:

-----------------------------208529943213031756281593958364

Content-Disposition: form-data; name="uploaded_data"; filename="polsl.gif"
Content-Type: image/gif

GIF89a_

What can be the cause of this strange behaviour?

1

1 Answers

0
votes

It looks like the binary string is being written and the writer is not writing out the non-printing characters. Or it is writing them out and whatever editor you are looking at the file with is filtering them. Try Base-64 encoding the data you receive before you write it to the file and see if that changes things. All GIFs by the way start with the string GIF89a.