0

I get content URI from getContent and I want to convert it to FileUpload

  object upload : FileUpload(mimetype) {
    override fun contentLength(): Long {
      TODO("return contentLength here")
    }
    override fun fileName(): String? {
      TODO("return fileName to use in the multipart request here")
    }
    override fun writeTo(sink: BufferedSink) {
      TODO("write the data here")
    }
  }
Omar khaled
  • 51
  • 3
  • 7
  • Use `DocumentFile` to get the length and display name. Use `ContentResolver` and `openInputStream()` to get an `InputStream` to use to get the data to write to the `BufferedSink`. This is very reminiscent to creating an OkHttp/Retrofit `RequestBody` for a content `Uri`, and that is described in [this blog post](https://commonsware.com/blog/2020/07/05/multipart-upload-okttp-uri.html) and [this blog post](https://cketti.de/2020/05/23/content-uris-and-okhttp/). – CommonsWare Jun 26 '21 at 18:37
  • how to write to the BufferedSink from inputstream – Omar khaled Jun 26 '21 at 18:54
  • That is covered in both of the blog posts that I linked to. Call `writeAll()` on the `BufferedSink`. – CommonsWare Jun 26 '21 at 19:02

0 Answers0