Jul 22
Wasting Time Trying To Accomplish The Impossible
Posted by jamersan | Posted in Porch Talk | Posted on 07-22-2009
Let’s say, hypothetically, that there was an online system where a fair amount of data needed to be entered. This system, hypothetically speaking, was cumbersome, slow, and just took all the fun out of data entry (and you know you love data entry). In our mythical world, it would be quite financially rewarding if you could automate the entry of data into said system.
So, I decided to write an Adobe Air application in Flex 3 to tackle this data entry automation. It has a built-in web browser that made it easy to create a quick app that would visit the site, login, go to the data entry page and fill out the form. Unfortunately, this form has one file upload entry that uses a little javascript/ajax combined with an old fashion form upload.
In an ideal world, I would just be able to set the value of the <input type=”file”> and submit the form. However, even though this is a desktop app, the browser’s security setup prohibits this from happening. In a web-based scenario, the benefits of such a limitation are easy to see. In my case, it was just frustrating. I can have my program “click” the browse button on the file upload, but could not find a way to manipulate the dialog that pops ups to select a file. I’ve tried about a million different methods to get this to work, but after two days of chasing this unicorn I decided to back off, regroup, and take another approach.
Examining the upload page, I noticed that the file upload was in it’s own form (not in the form of the rest of the data entry). The data entry page contained an iframe, which pointed to another page that contained the file upload information. This way, the file upload happened as soon as you chose a file and it displayed on the data entry page. I modified my program to make this iframe point to a php file on my server. This php file grabbed an image from the server, posted it to the data entry site posing as the form on the original page. I even passed in cookies and session information so it looked as legit as possible. However, the image is not uploading. After reviewing the page for several hours, I have come to the conclusion that there is more javascript/ajax involved in this upload than I had previously hoped and expected. There MUST be something firing on that form once an image is selected that my script is not doing.
I’ll try to spend more time tonight reviewing the data entry’s javascript to see if I can find the culprit. Unfortunately, it has thousands of lines of ill-formatted javascript with all the spaces and lines removed. It makes for a fun night of code review!