android - How can I properly send a Synced External Application Image to a RESTful WCF -


i'm newbie android, i'm trying send images android restful wcf.

by i'm being able select images gallery , sending them server.

the wcf expecting image stream

but i'm having problems synced images stored in tablet facebook or g+ photos. (i don't know if cached or something)

i'm using function path of image

public static string getrealpathfromuri(context context, uri contenturi) {          string path = null;          if (contenturi.getscheme().tostring().compareto("content")==0)          {             string[] proj = { mediastore.images.media.data };                        cursor cursor = context.getcontentresolver().query(contenturi, proj, null, null, null);             int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data);                      cursor.movetofirst();             path = cursor.getstring(column_index);          }          else           {              path = contenturi.getpath();          }          log.i(tag, path);          return path;         } 

with kind of images internet path like:

https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash4/s2048x2048/432098_10151223392360790_398885469_n.jpg

just clarity , remark. "content" scheme.. path "if " like:

content://com.sec.android.gallery3d.provider/picasa/item/5703464571893262194 

to send server im using multipartentity, because saw in others post here in so, this:

 ((multipartentity) oinputentity).addpart(                             "filecontents",                             new filebody(new file(utilities.getrealpathfromuri(context,                                             imageuri)),   "image/jpeg")); 

with kind of images getting filenotfoundeception think it's because image path internet path, multipartentity don't know how retrieve it,

so changed method download image , working code

public static file getfilefromuri(context context, uri contenturi) {              string path = intutilities.getrealpathfromuri(context, contenturi);              log.i(tag, path);              final file file;              if (path.startswith("http") || path.startswith("/http") )              {                  //if image form internet lets download , save in our directory , return file                 // determine uri of camera image save.                 final string fname = "bir" + uuid.randomuuid() + ".jpg";                 final file root = new file(environment.getexternalstoragedirectory().getabsolutepath() + file.separator + "bir");                 root.mkdirs();                 file = new file(root, fname);                       try {                      final url url = new url(path);                      final httpurlconnection urlconnection = (httpurlconnection) url                              .openconnection();                      urlconnection.setrequestmethod("get");                      urlconnection.setdooutput(false);                      urlconnection.connect();                      final fileoutputstream fileoutput = new fileoutputstream(file);                      final inputstream inputstream = urlconnection.getinputstream();                       @suppresswarnings("unused")                     int downloadedsize = 0;                       byte[] buffer = new byte[1024];                      int bufferlength = 0;                      while ((bufferlength = inputstream.read(buffer)) > 0) {                          fileoutput.write(buffer, 0, bufferlength);                          downloadedsize += bufferlength;                      }                      // close output stream when done                      fileoutput.close();                 } catch (malformedurlexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }              }              else              {                            file = new file(path);              }              return file;             }  

  ((multipartentity) oinputentity).addpart(                                 "filecontents",                                 new filebody(utilities.getfilefromuri(context,                                                 imageuri),       "image/jpeg")); 

but i'm not comfortable solution, seems double effort, turned off wifi , 3g in tablet, turned off , on tablet iself , still see images, i'm guessing got copied locally or cached on tablet when synced first time. looked them when attached computer (in windows explorer) see if there, dont see them, maybe i'm doing wrong or dont know storage folder.

the main reason dont solution if don't have internet on moment, image not downloaded, , app i'm making supposed work offline, , well.. image there, there shouldn't request internet guess local image.

being said this, there way find real/physical path of photos synced, have http or https scheme send images using multipartentity?

or proper way send images server?

i appreciate help

from chooser dialog , can bitmap

chooser-->$result->getdata() = imageuri

from imageuri, bitmap running following code:

bitmap bitmap = mediastore.images.media.getbitmap(this.getcontentresolver(), imageuri); 

once bitmap..,

you can put filesink

you can use hashmap cache in memory

mbitmap = bitmapfactory.decodestream(     mcr.openinputstream(imageuri),  null,  options);  outputstream os = new fileoutputstream(f); mbitmap.compress(bitmap.compressformat.jpg, minval, os); mload.memorycache.putbig(file.touri().tourl().tostring(), mbitmap); 

and can http post bitmap directly loading bytearray entity...

case post:  httppost httppost = new httppost(url);                   bytearrayoutputstream stream = new bytearrayoutputstream();                  float tmp = (float) 1024 * 1024 / bmp.getbytecount(); int minval = (math.round(tmp * 100) < 101) ? math.round(tmp * 100): 100; if (bmp.compress(bitmap.compressformat.jpeg, minval, stream)){           httppost.setentity(new bytearrayentity(stream.tobytearray())); }else{ //todo need format actual message     handler.sendmessage(message.obtain(handler,     httpconnection.did_error, new exception("err bitmap ng")));                     } 

background on post method here

lazyloader project template use.

so why use mimemultipartentity file when can operate directly on bytes in bitmap? have uri, bitmap , use bitmap/ uri pair basis of interface memcache, interface http post, interface filesink used retrieve local file when have cachemiss. minimize doing on basis of file.

think using map [hashon(uri.tostring() :: bitmap] store images process locally. when want post image , can retrieve map , post bytes directly in "bytearrayentity".


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -