How to POST InputStream as the body of a request in Retrofit?

前端 未结 5 694
刺人心
刺人心 2021-01-18 00:52

I\'m attempting to do a POST with the body being an InputStream with something like this:

@POST(\"/build\")
@Headers(\"Content-Type: application/tar\")
Respo         


        
5条回答
  •  误落风尘
    2021-01-18 01:09

    TypedInput is a wrapper around an InputStream that has metadata such as length and content type which is used in making the request. All you need to do is provide a class that implements TypedInput which passed your input stream.

    class TarFileInput implements TypedInput {
      @Override public InputStream in() {
        return /*your input stream here*/;
      }
    
      // other methods...
    }
    

    Be sure you pass the appropriate return values for length() and mimeType() based on the type of file from which you are streaming content.

    You can also optionally pass it as an anonymous implementation when you are calling your build method.

提交回复
热议问题