public class InputStreamRequestBody extends RequestBody {
private final MediaType contentType;
private final ContentResolver contentResolver;
private final Uri uri;
public InputStreamRequestBody(MediaType contentType, ContentResolver contentResolver, Uri uri) {
if (uri == null) throw new NullPointerException("uri == null");
this.contentType = contentType;
this.contentResolver = contentResolver;
this.uri = uri;
}
@Nullable
@Override
public MediaType contentType() {
return contentType;
}
@Override
public long contentLength() throws IOException {
return -1;
}
@Override
public void writeTo(@NonNull BufferedSink sink) throws IOException {
sink.writeAll(Okio.source(contentResolver.openInputStream(uri)));
}
}
Last active
January 24, 2021 15:13
-
-
Save raghunandankavi2010/4cd62bc1c58751e02089dec90d7cd094 to your computer and use it in GitHub Desktop.
Request Body for input stream
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment