java - Image URL to ParseFile? -


i have parse android app implementing facebook sign up. stuck on grabbing images set profile pictures of new parseuser's. have used facebook graph api retrieve correct url (i have checked plugging browser, shown right profile picture), need way turn url byte array (byte[]) can save parsefile field of our parseuser's profile picture. have looked @ these questions:

java.net.url read stream byte[]

efficiently read file url byte[] in java

get image given url , convert byte array

none of these have worked. trying use apache ioutils, in solution second link. here current code asynctask:

private class setprofpicwithurl extends asynctask<url, integer, byte[]> {         @override         protected byte[] doinbackground(url... imageurl) {             log.i("setprofpicwithurl", "invocation, url: " + imageurl[0]);             inputstream = null;             byte[] bytes = null;             try {                 = imageurl[0].openstream();                 bytes = ioutils.tobytearray(is);             } catch (ioexception e) {                 e.printstacktrace();             }             {                 if (is != null) try {                     is.close();                      if(bytes == null){log.e("loginactivity", "bytes null int setprofpicwithurl");}                     final parsefile imagefile = new parsefile("image.jpg", bytes);                     imagefile.saveinbackground(new savecallback() {                         @override                         public void done(parseexception e) {                             if (e == null) {                                 log.i("loginactivity", "getcurrentuser.put");                                 parseuser.getcurrentuser().put(parseutils.parse_profile_image, imagefile);                                 parseuser.getcurrentuser().saveinbackground();                             } else {                                 e.printstacktrace();                             }                         }                     });                 } catch (ioexception e) {                     e.printstacktrace();                 }             }             return bytes;         }     } 

now when code executes, no error logs, , parsefile created. however, no profile pictures load within app, , when click examine file in dashboard, error message:

the file “tfss-0280f98d-7180-4528-9d24-3ec47d3b25d4-image.jpg” not opened because empty.

honestly, i'm @ loss. i've spent more time on 1 photo issue other part of implementing facebook login. , way our database set up, not ideal create field save url , load picasso. issue appreciated!

directly save imagefile profile picture :

final parsefile imagefile = new parsefile("image.jpg", bytes); parseuser.getcurrentuser().put(parseutils.parse_profile_image, imagefile); parseuser.getcurrentuser().saveinbackground(new savecallback() {     @override     public void done(parseexception e) {         if (e == null) {             log.i("loginactivity", "profile saved succesfully");          } else {             e.printstacktrace();         }     } }); 

edit :

use image byte array url.

try {     java.net.url img_value = new java.net.url(imageurl);             bitmap micon = bitmapfactory             .decodestream(img_value.openconnection()                     .getinputstream());     if (micon != null)         imgbytearray = encodetobytearray(micon); } catch (exception e) {     e.printstacktrace(); }   public byte[] encodetobytearray(bitmap image) {     log.d(tag, "encodetobytearray");     bitmap b= image;     bytearrayoutputstream baos = new bytearrayoutputstream();     b.compress(bitmap.compressformat.jpeg, 100, baos);     byte[] imgbytearray = baos.tobytearray();      return imgbytearray ; } 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -