0

Alright, so let me preface this by saying that I'm really unsure as to what I'm doing here and if it is at all possible.

I'm trying to build an android app that will interact with a pre-existing website. The site has a field to browse for a file, and a button upload it. Hitting upload opens a /upload.cgi which seems to do the uploading itself before redirecting to a results page.

Is it possible to use the underlying javascript to upload a file without having to use the pre-existing GUI that the website presents? I would like to just use my own interface, but have it interact with what the website has.

Thanks, and apologies for the vagueness.

SNyamathi
  • 658
  • 6
  • 10

1 Answers1

1

You maybe able to get it working using the Java/JavaScript bridge to submit the form for you (using a WebView). But my guess is it would be more trouble than it's worth. And you should be able to do it directly in Java using a post.

Files in HTML forms are normally uploaded using a multipart form encoded post body. Something like this:

<form enctype="multipart/form-data" action="upload.cgi" method="POST">
   <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
   Choose a file to upload: <input name="uploadedfile" type="file" /><br />
   <input type="submit" value="Upload File" />
</form>

All you need to do is create the same post request that the form would generate. Here are a few links to get you started with creating multipart post request on Android.

How use multipart/form-data upload picture/image on Android

http://w3mentor.com/learn/java/android-development/android-http-services/example-of-multipart-post-using-android/

http://www.17od.com/2010/02/18/multipart-form-upload-on-android/

http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/

Here's a debugging tip if you get stuck: You can installed fiddler as a reverse proxy on the CGI server, then you can watch both requests (HTML and Java) as they happen to compare them for differences. http://www.fiddler2.com/fiddler/help/reverseproxy.asp just remove it for production.

Community
  • 1
  • 1
eSniff
  • 5,713
  • 1
  • 27
  • 31