URL Access Scripting Form Data

I think that being able to post form data with Applescript is one of the kewlest things to come along since sliced bits, but I’ve run into a frustrating problem. Here’s the situation: I send files to be printed to a vendor via a web page. The page has me fill out info about the print job as well as select the file to send; submitting the form posts the order info and sends the file. When I try to do this with Applescript I always get the error “File (my file) contained no data.” from the vendor. I have tried every coersion of the file data I could think of (alias, alias as text, as URL, as string, as “file:///MyHardDrive/File”, etc.), and it will not recognize the form data as a file. It appears that form data can only be text. Anyone have an idea how to make a file part of the form data string?


set the action_URL to "http://www.somepagewithaform.com/cgi-bin/Upload"
set the query_results_file to (path to desktop folder as text) & "Query Results"
set the file_to_send to (choose file)
set the order_number to text returned of (display dialog "Enter order number." default answer "")

--here's where I need to make a file part of the form data

set form_data to "order=" & order_number & "&file=" & file_to_send

tell application "URL Access Scripting"download the action_URL to file ¬
  the query_results_file form data form_data with progress
end tell

Me, too! …a…what’s a sliced bit?

How are the files selected? Are they FTP transfered, or are they binary tacked on as the value to key “&file” in form data? I would like to check out the url of the form page…

I believe this is because you are just sending the location string and not the file. I don’t think the cgi knows how to come back for the file. But you probably knew that. Does the form allow you to input a web url of an uploaded file for your submittal? If so, then you could use URL Access to upload your file to your local server, then send its url as part of the form. Same upload time as web form way.

You might have to turn your file data into Unicode text or what ever raw data text the cgi supports for it to recognize the file, but that seems a little heavy-handed. Again, I would like to know ‘how’ the form usually gets the file, and how you are ‘required’ to input its location. Can you post the form page url to the list?

Well…I was going to say “sliced bread” but it seemed dated.

Ah - the page is not mine, it is a vendor we use to print continuous forms so I don’t have any means to upload to a local server. It’s all internet. The form only allows me to select a file; the html is .

I’d like to, however I don’t know what they’d say about it or what my boss would think about giving out our account number. Part of the reason I want to script the form is that to get to the upload page I first have to sign-on with our account information. The page is from Block Graphics, Inc. [urlhttp://www.blockgraphics.com/BBS/[/url]. This is the sign-on page, and with the proper account number and zip code it generates a page http://www.blockgraphics.com/cgi-bin/Upload but it’s not an actual html file, it is a result of either sucessful or unsucessful sign-on. The form gets the file just by using an input type of file. When using a browser it is a field with a “Browse…” button next to it; clicking the button puts up a choose file dialog and the file name appears in the field after selecting a file on my hard drive. I’ve already tried parsing the file location into Unicode text, it seems to be a problem with URL Access Scripting allowing only text values for form data string and the cgi is expecting a file path. Do you mean I should turn the data of the file into Unicode text? Hmmmmmm… You’re right, that’s a long way around, but it makes sense. Well, it’s always a .sit file that I send; would that convert into Unicode easily? Such as…read file → text → Encode URL?

Sounds like it could get heavy if it’s a large file. I made a test page on my own web site with a input type=file form, but the cgi only emails the text of the fields. The result looked like plain “//HardDrive/testfile.sit” when it got posted, so I thought that’s all that a browser was doing when sending form data that is a file. But alas, as that, or as any variation of a file path the page returns the no data error. When I try making just an alias or an alias turned into a URL part of the form data, URL Access errors with “Cannot make -thetest- into a string.”

Thanks for checking it out. Ya - too many variables and security stuff. I’m not hopeful about there being any Applescript guru with Block; their support for anything Mac has been slim at best, and the tech I have talked to before wasn’t up to date on Mac settings for generating a ps file even.

The java they use appears to simply verify text length of some of the fields and checks for required field entries (I’m starting to get a sense of java structures). The no binary clause is that they don’t want to deal with email hassles from different encoding schemes of the hundreds of mailers people can use (that’s the sense I got from them). But it makes me think that reading the .sit file data as text and sending it in the form data string might work.

I’ll give it a try next time a job comes through and post the results.
Thanks again. urKewl.

Nope. Well, I didn’t do much experimentation. I tried just reading the sit file (read/write) and dumping it into the form data, but the BBS still returned an error. Different error this time, tho. Previously, it would tell me “The file <path to file, name of file…different depending on the format I used to specify the file path> contained no data, be sure that the path is correct.” This time it reported “The file <nothing, blank, not even a space> contained no data, be sure that the path is correct.”


Just rambling a bit, but…

I have set up a CGI in-office and done some testing (having the CGI take an uploaded file, rename it, display it…not much doing…)

The only way I could upload a file is by running it through the “encode as MIME format” from Akua Sweets, then uploading that. Again, though, if they’re disallowing binary, I don’t know if this is help or not.

Again, just letting my brains run all over the page (oop-there go some now).


The field values and names must be URLEncoded and be in the format:


The problem I am having is when the text to post is greater than 32K. I understand the mac textedit heritage, but does anyone have any idea how to convince URL Access Scripting that it should not treat the POST data as text?

Thanx in advance.

Does increasing the memory settings (get info) help. I’ve had scripts that try to deal with lots of data which results in an out of memory error work properly if I set the minimum and preferred memory allocation of the script application to something more than the default 200 K.

It’s what I’m looking for as well. The script can read a file as data rather than text, but URL Access Scripting can’t parse the data type into a string. Ideas anybody?

This sounds encouraging. When the read file text is encoded as MIME format with Akua Sweets it is accepted as form data by URL Access Scripting? I downloaded Akua Sweet hoping it would do just that but haven’t had the chance to try it.

I’ll post my results. Thanks for spilling your brains!


Drat! Same result when encoding the file in MIME format. The server responded to my attempt:

the file: w. is EMPTY. Please make sure the path you specified for StuffIt (c)1997-1998 Aladdin Systems, Inc., http://www.aladdinsys.com/StuffIt/ in the upload form is correct and the file is properly made.

I see that it’s getting the data of the file (it begins with the copyright and web address), but is not recognizing it as a file (it’s supposed to read the file name and put a “w.” in front of it).

Guess their anti-binary policy is across the board.

Thanks for the ideas, tho. Can’t say I didn’t try.