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

前端 未结 5 640
刺人心
刺人心 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:07

    My solution was to implement TypedOutput

    public class TypedStream implements TypedOutput{
    
        private Uri uri;
    
        public TypedStream(Uri uri){
            this.uri = uri;
        }
    
        @Override
        public String fileName() {
            return null;
        }
    
        @Override
        public String mimeType() {
            return getContentResolver().getType(uri);
        }
    
        @Override
        public long length() {
            return -1;
        }
    
        @Override
        public void writeTo(OutputStream out) throws IOException {
            Utils.copyStream(getContentResolver().openInputStream(uri), out);
        }
    }
    

提交回复
热议问题