I was having an interesting conversation with Chuck, who needed to post a file up to a server. The process seemed simple enough, it's a long-standing requirement, create a form, add a File Upload field and so on, but it just didn't work.
After examining the server for a bit I realized that it's not the code which is wrong, it's the approach. The Form procedure has grown up over the years, and while it's possible to "drive" the form automatically, it's also more complicated now because a form expects to go through a number of stages. You'd have to make at least two calls, the first to generate the form, the second to do the POST while at the same time preserving the Session Cookie, and FormState value. It's do'able, but seems like a lot of work.
Fortunately there's an easier way.
If you create a NetWebPage, rather than a Form, then you can simplify things a lot, because a Page is parsed exactly like a form (so all the fields are available for you to use) and a page doesn't have the inherent "expectations" that a form has.
On the sending side, Chuck has based his sender on the example "Examples\NetTalk\WebClient\Web Client Send File\websend.app".
That contains the following code;
net.SetValue('whatever',something)
net.SetValue(FieldName,FileName,true)
net.Post(URL,'')
As you can see any number of fields can be included in the post, and disk files can be included.
On the server side, if the procedure is a NetWebPage, not a NetWebForm, then any embed code can be added to do whatever you like with the fields. The contents of the simple text fields are in
p_web.GetValue('whatever')
and the incoming files can be saved by doing
p_web.SaveFile('fieldname','name on disk')
The name of the file being sent, _including_ the path of the sender machine is in
p_web.GetValue('fieldname')
StringTheory has a method called FileNameOnly that strips off the path. So putting it all together, let's say the name of the incoming field is 'FileFromClient' then the code to save the incoming file, into a directory called c:\temp\incoming looks like this;
str StringTheory
...
str.SetValue(p_web.GetValue('FileFromClient'))
str.SetValue('c:\temp\incoming\' & str.FileNameOnly())
p_web.SaveFile('FileFromClient',str.GetValue())
Cheers
Bruce