Tag: amazon s3

使用OkHttp上传到预先签署的S3 URL失败

当我尝试使用OkHttp 3.9.1将文件上传到Amazon S3的预签名URL时,出现SSLexception: SSLException: Write error: ssl=0xa0b73280: I/O error during system call, Connection reset by peer 这是同样的问题,在另一个SO问题,但在我的情况下,它总是失败。 我只上传大小超过1MiB的文件,我还没有尝试过小文件。 正如我在这个问题的答案中提到的,切换到Java的HttpURLConnection解决了这个问题,上传完美。 这里是我的RequestBody实现(在Kotlin)从Android的Uri上传文件,我使用OkHttp的.put()方法: class UriRequestBody(private val file: Uri, private val contentResolver: ContentResolver, private val mediaType: MediaType = MediaType.parse(“application/octet-stream”)!!): RequestBody() { override fun contentLength(): Long = -1L override fun contentType(): MediaType? = mediaType override fun writeTo(sink: BufferedSink) { Okio.source((contentResolver.openInputStream(file))).use […]