0

Im building an app, which makes it possible to up and download image files. Im receiving an inputstream from a server when i ask for image files. if i call the method just after i uploaded the picture without closing my app first, its possible to decode the stream to a bitmap and everything works fine.

But if i close first, i doesn't work and the content looks different. the string i get looks like "{"Attachment":"/9j/4S5RXhp....."

Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
annika
  • 51
  • 1
  • 4
  • Annika, not getting your question properly, can you please explain in simple language? – Pratik Dasa Nov 19 '14 at 12:39
  • its fine when i send the request just after i took a picture and then uploaded the image file with my app. im having troubles when i take a picture, upload it and then close my app to start it again and request the image file ive uploaded before. i get the skimage decoder returned null error everytime when trying to parse to a bitmap allthough it works fine in the other case. i decoded it to a string and found out that the string i get in the second case looks totally different just like described above – annika Nov 19 '14 at 12:46
  • That means, first you upload image to server and then you close the app and then again you open the app and trying to get that images? – Pratik Dasa Nov 19 '14 at 12:49
  • yes, and the problem i have i that i just cant find out why i cant decode it. – annika Nov 19 '14 at 12:55
  • can you please post your image url here, which you are getting from server? – Pratik Dasa Nov 19 '14 at 12:57
  • http://postimg.org/image/pe72lehgz/ does not work – annika Nov 19 '14 at 12:59
  • This image url is not proper. Its damaged, please check that you uploading image proper and you getting image proper. – Pratik Dasa Nov 19 '14 at 13:00
  • everything is fine http://postimg.org/image/lstbw34ad/ – annika Nov 19 '14 at 13:01
  • no, if everything is fine then you getting wrong url, because its not full url, image url must have its extension with it like, postimg.org/image/pe72lehgz.jpg – Pratik Dasa Nov 19 '14 at 13:02
  • i do not have an url i make a connection with, im using third party library and the api documentation is bad – annika Nov 19 '14 at 13:02
  • my question is how to create a bitmap out of this http://postimg.org/image/pe72lehgz it must be possible somehow – annika Nov 19 '14 at 13:05
  • visit this links may be it will useful to you: http://stackoverflow.com/questions/18630080/android-byte-array-to-bitmap-how-to – Pratik Dasa Nov 19 '14 at 13:07
  • now i dont get any error but when i want to display it, there is no picture – annika Nov 19 '14 at 14:41

1 Answers1

0
            BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            StringBuilder responseStrBuilder = new StringBuilder();

            String inputStr;
            while ((inputStr = streamReader.readLine()) != null)
                responseStrBuilder.append(inputStr);

            JSONObject att = new JSONObject(responseStrBuilder.toString());

            byte[] bytes = Base64.decode(att.getString("Attachment"), Base64.DEFAULT);
            bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
humi.dev
  • 126
  • 1
  • 3