Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

File Transfer using HTTPPost


simon Oct 22, 2012 02:44 AM

CR1000-OS25

I've been able to use the HTTPPost() instruction to pass data to a php script on a server using HTTP POST with a brief Header definition to be used in the HTTPPost() instruction.

The help in CRBasic indicates that the Contents parameter can be the name of a file on the data logger. I want to be able to POST files to the server and I thought that this was going to be a breeze to set up. Just point it at the file and hey presto, but I found that not not to be the case.

What happens is that the file that has been referenced is opened and the text inside is used as the Contents, expecting that this data is in the correct format for the transfer. Not quite what I was hoping for.

I was able to use some info that I found in another forum post here http://campbellsci.com/forum/messages.cfm?threadid=FBCE6801-D973-4056-95F23DF26B013BBF to assist me to create the appropriate Contents parameter to allow me to POST a text file to the server. I read the contents of the file into a string variable and used that String variables (with some extra header information) to form the appropriate Contents parameter. Read the forum post linked above for details. I used that as a basis and tweaked from there.

Now, I am looking to extend this further such that files of any type could be transmitted using POST. My first test was a jpg file. The issue that I'm hitting is that these files can (and often do) contain the NULL (0x00) byte and the behaviour of the String variable type when NULL is encountered causes only part of the file to be sent.

I've written code to assemble the string variable used in the Contents parameter of HTTPPost(), byte by byte using the Var(1,1,i) syntax, but the HTTPPost() instruction still truncates the data at the first NULL it sees. I'm guessing that there is no way around this (yet).

While possible, I'd expect that even text file transfers using the HTTPPost() operation is probably getting to the point of being "difficult to implement" for most CRBasic users. Is it possible to have the HTTPPost() instruction extended in future OS versions to have the ability to actually send files using POST, with the OS handling the headers and the presentation of the data to the server in the appropriate format?

Thanks

Simon

Log in or register to post/reply in the forum.