3

I'm trying to upload an image using POST. Then on the server to get the POST data, I use:

data: read system/ports/input

...but it seems that the data is truncated.

There doesn't seem to be some specific boundary where the data are truncated. I'm uploading images in range from cca 15-200kB, and the resulting data are few hundreds to few tens of kB long, so there's no artificial boundary like 32'000 bytes.

Does anyone have experience with getting data from POST?

Dan Lee
  • 71
  • 5
  • @rebolek I saw your question in the chat room and decided to answer it here. I'm a brand new user and have no access to chat. – Dan Lee Sep 17 '14 at 22:48
  • thanks to your fantastic response now you have enough reputation to participate in chat :) – rebolek Sep 18 '14 at 05:40

2 Answers2

4

The read action on system/ports/input works at a low level, like a stream. Continuous reads will return partial data until the end of input is reached. The problem is that system/ports/input will return an error at the end of input instead of none! or an empty string.

The following code works for me to read large POST input:

image: make binary! 200'000
while [
    not error? try [data: read system/ports/input]
][
        append image data
]
Dan Lee
  • 71
  • 5
  • Thanks! I'm going to try it. – rebolek Sep 18 '14 at 05:37
  • So I've tried it and unfortunately, I have different experience. READ on `system/ports/input` doesn't throw an error but is stuck waiting for data and does not timeout. – rebolek Sep 18 '14 at 06:01
  • What version and what OS do you use? I got an empty string at the end; see below. – sqlab Sep 19 '14 at 06:39
  • I'm using the latest Atronix 64-bit build on Windows 7 Pro with Apache 2.4.3.0 (32-bit). I noticed that the standard input port behaves differently on the command line that it does in CGI. On the command line, I can read continuously without getting an error. – Dan Lee Sep 20 '14 at 13:43
1

with r3-64-view-2014-02-14-1926d8.exe I used

while [
    all [
       not error? try [data: read system/ports/input]
       0 < probe length? data
    ]
][
    append image data
]
print length? image

And did

D:\own\Rebol>r3-64-view-2014-02-14-1926d8.exe read-img.r < r3-64-view-2014-02-14-1926d8.exe > err.txt

and got

.
.
16384
16384
16384
2048
0
1181696
sqlab
  • 6,412
  • 1
  • 14
  • 29
  • Can't find that build, but I tried the [latest Atronix Windows 64-bit build](http://atronixengineering.com/r3/downloads/r3-64-view.exe) on Windows 7 Professional and Apache v2.4.3.0 (32-bit). This combination works for me. – Dan Lee Sep 18 '14 at 17:06