尝试从 AWS url 获取输入流时如何解决 java.io.FileNotFoundException

how to resolve java.io.FileNotFoundException when trying to get inputstream from AWS url

我的主要目标是获取我从 AWS 获取的图像的方向,部分代码是首先获取我需要为其传递 URI 的 imputStream,我正在做 Uri.parse(url)获取 uri,当我尝试获取 URI 时,我得到

java.io.FileNotFoundException: No content provider

URL 通过:

https://xxx-2.amazonaws.com/YRINWoUKBOW97VXvpnRelWioT2r2/6d95054e-8a6c-4a61-a4ff-18f63aa187b4/1/thumbnail.png?X-Amz-Algorithm=AWS4-HMAC-xx&X-Amz-Date=20220221T203050Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1800&X-Amz-Credential=AKIAJGEUAZB7E5XX6NPA%2F20220221%2Feu-west-2%2Fs3%xx&X-Amz-Signature=d3839d925efc6fffff417e25af1e6bad28ed10ef27d1c4460d20470

错误

java.io.FileNotFoundException: No content provider: https://xxx2.amazonaws.com/YRINWoUKBOW97VXvpnRelWioT2r2/6d95054e-8a6c-4a61-a4ff-18f63aa187b4/1/thumbnail.png?X-Amz-Algorithm=AWS4-HMAC-xxx&X-Amz-Date=20220221T203050Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1800&X-Amz-Credential=AKIAJGEUAZB7E5XX6NPA%2F20220221%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Signature=d3839dffff925efc6417e25aff414d76b8ed10ef27d1c4460d20470

这是我的代码

private fun getExifOrientationFromURI(context: Context, url: String): Int {
        var orientation: Int = 1
        try {
    context.contentResolver.openInputStream(Uri.parse(url)).use { inputStream -> //ERROR IS AT THIS LINE 
                if(inputStream == null) return  orientation
                val exif = ExifInterface(inputStream)
                orientation =
                    exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
            }
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return orientation
    }

我做错了什么?

openInputStream() on ContentResolver 不支持 httphttps URLs,只支持 file, content,和 android.resource Uri 值。您需要为 URL 使用 HTTPS API,例如 OkHttp。