Upload image to server by HTML FIleUpload on Android

noone14

New Member
I'm trying to develop a mobile application for some site, that using HTML form for data transfer. Currently I'm developing for Android, but this app should be also on iOS and WP7 (that's why I've chosen PhoneGap).The form I'm using has \[code\]<input type="file">\[/code\] tag and I should pass image itself through it because I haven't access to the server part. What I've tried:[*]To use \[code\]<input type="file">\[/code\] tag as it was on form but it doesn't open filepicker dialog.[*]To use PhoneGap methods for getting image in base64 format and attach it to the form parameters but server doesn't recognize them as a valid file.For accomplishing this I'm using next function:\[code\]function fileUpload (url, fileData, fileName) {var fileSize = fileData.length, boundary = "12352134", xhr = new XMLHttpRequest();xhr.open("POST", url, true); // simulate a file MIME POST request.xhr.setRequestHeader("Content-Type", "multipart/form-data, boundary="+boundary);xhr.setRequestHeader("Content-Length", fileSize);var body = "--" + boundary + "\r\n";body += 'Content-Disposition: form-data; name="imagen"; filename="' + fileName + '"\r\n';body += "Content-Type: image/jpeg\r\n\r\n";body += fileData + "\r\n";body += "--" + boundary + "--";xhr.send(body);return true;\[/code\]}I can't use Ajax for passing just an image because I don't have access to form and all data must be integral.
 
Back
Top