1

I want to download the image from reome URL and I get SSL error

 String imgURL="http://whootin.s3.amazonaws.com/uploads/upload/0/0/23/82/Note_03_26_2013_01_10_55_68.jpg?AWSAccessKeyId=AKIAJF5QHW2P5ZLAGVDQ&Signature=Za4yG0YKS4%2FgoxSidFsZaAA8vWQ%3D&Expires=1364888750";

   final ImageView  ivCurrent;
   ivCurrent = (ImageView)findViewById(R.id.imageView1);

  // calling DownloadAndReadImage class to load and save image in sd card

     DownloadAndReadImage dImage= new DownloadAndReadImage(imgURL,1);

     ivCurrent.setImageBitmap(dImage.getBitmapImage());

The error:

javax.net.ssl.SSLException: Read error: ssl=0x19a4a0: I/O error during system call, Connection reset by peer
PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58
saravanan
  • 1,082
  • 1
  • 15
  • 30

3 Answers3

1

Your question make no sense because we know nothing about DownloadAndReadImage class, By the way I think you need to add these two permissions in your manifest:

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

P.S If you are looking for a great ImageLoder library, I suggest you Android Universal Image Loader:

https://github.com/nostra13/Android-Universal-Image-Loader

Ali
  • 2,012
  • 3
  • 25
  • 41
  • 1
    @SotiriosDelimanolis Perhaps the best is a big word, but I've added this library in several projects and it works great. – Ali Apr 01 '13 at 14:09
0

In my project I download and store images in SD card using InputStreams in the following way:

URL url = new URL(imageUrl);

InputStream input = url.openStream();

try {

    // The sdcard directory e.g. '/sdcard' can be used directly, or
    // more safely abstracted with getExternalStorageDirectory()
    String storagePath = Environment.getExternalStorageDirectory()
                                    .getAbsolutePath();

    int barIndex = imageUrl.indexOf("/");
    String path = imageUrl.substring(barIndex + 1) + ".jpg";

    String sdcardPath = storagePath + "/myapp/";

    File sdcardPathDir = new File(sdcardPath);

    sdcardPathDir.mkdirs();

    OutputStream output = new FileOutputStream(sdcardPath + imagemId + ".jpg");

    try {
        byte[] buffer = new byte[4 * 1024];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
            output.write(buffer, 0, bytesRead);
        }
    } finally {
        output.close();
    }

} finally {
    input.close();
}

As @NullPointer pointed out, don't forget to check the manifest file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
RMalke
  • 4,048
  • 29
  • 42
0

You are Connect to an HTTPS/HTTP URL via and the SSL certificate provided by the site is not trusted by the devise you are running the code on.

setting up trust in the Apache HTTP Client.

Community
  • 1
  • 1
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54