android - 在android中从https URL下载和保存图像

标签 android image ssl download

我有这个功能可以在设备中下载和保存图像 -

public void DownloadFromUrl(String WebURL, String fileName) {
        try {
            URL url = new URL(WebURL);
            file = new File(context.getFilesDir() + fileName+".jpg");

            long startTime = System.currentTimeMillis();
            URLConnection ucon = url.openConnection();
            InputStream is = ucon.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);

            ByteArrayBuffer baf = new ByteArrayBuffer(50);
            int current = 0;
            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(baf.toByteArray());
            fos.close();
        } catch (IOException e) {
            Log.d("ImageManager", "Error: " + e);
        }
    }

如果我提供 https URL,它无法保存图像。关于如何下载和保存 https 图像的任何指示?

最佳答案

希望此链接对您有所帮助。 Tonikami 上传/下载图片。

https://www.youtube.com/playlist?list=PLe60o7ed8E-Q7tqKNPnWFdUoeniqH_-A9

关于android - 在android中从https URL下载和保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35332747/

相关文章:

python - 无法在后端使用 python flask 和 ssl 验证 Facebook webhook 订阅中的 URL

android - 从 GET 获取状态码 400

javascript - 包含大量图片的网页 : slow scrolling?

ios - 图片太多,应用程序太大

authentication - 请求已中止 : Could not create SSL/TLS secure channel.(RestSharp、SSL 客户端证书)

c++ - BB10 QNX Momentics IDE 中的 SSL 握手失败

Android独立服务怎么来的?

android - 苹果。找不到模块 'appium-base-driver'

javascript - 错误: getApplication() has protected access in ReactNativeHost

android - 相同的图片,但同一智能手机上的分辨率不同