java - How do I send a ByteArray from Android to PHP? -
i'm trying send jpg out of app php listener , seems bytearray right way handle this. however, when request have gets server, has filename parameter (which separate) not bytearray param. in case of bytearray it's missing both key , value of field.
in debugger, can see data in request... perhaps i'm not collecting correctly on php side?
here relevant parts of code... appreciated (as advice in alternate, more effective, way).
android:
try { part[] parts = new part[2]; bytearraypartsource ps = new bytearraypartsource( printfilename, bitmapdata); parts[0] = new filepart("filedata", ps); parts[1] = new stringpart("filename" ,printfilename); filepost.setrequestentity(new multipartrequestentity(parts, filepost.getparams())); } catch (exception e) { log.d("my_debug", e.tostring()); } try { int statuscode1 = client.executemethod(filepost);
php:
$targetpath = "./" . $_request['filename'] ; $newfilepath = $targetpath; $fh = fopen($newfilepath, 'wb'); //tried both of these, neither seems work... fwrite($fh, $globals["http_raw_post_data"]) or die("unable write data"); //and fwrite($fh, file_get_contents('php://input')); fclose($fh); echo "success!";
check link here had posted complete code upload image php server
android httpclient file upload data corruption , timeout issues
http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html
it checked , tested thing hope helps :)
Comments
Post a Comment