Skip to content

๐Ÿ“š A android library for get upload progress from request body using retrofit. Support multiple file upload โฌ†.

Notifications You must be signed in to change notification settings

Musfick/retrofit-kotlin-upload-progress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Retrofit Request Body With Progress(Kotlin)

Introduction

This library allows you to get upload progress from Retrofit Request Body

Support

โœ… Single File Upload
โœ… Multiple File Upload

Usage

This library allows you to specify your service interface as:

interface Service {
    @POST("/posts")
    fun createPost(@Body body: RequestBody): Response<Post>
}

And then in your repository:

val bodyBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)

bodyBuilder.addFormDataPart("title", "Post Title")
bodyBuilder.addFormDataPart("description", "Post Description")

//File
bodyBuilder.addFormDataPart("image", file.name, file.asRequestBody("image/*".toMediaTypeOrNull()))
bodyBuilder.addFormDataPart("video", file.name, file.asRequestBody("video/*".toMediaTypeOrNull()))

val requestBody = bodyBuilder.build()
val requestBodyWithProgress = ReqBodyWithProgress(requestBody){progress ->
    //If you use logging interceptor this will trigger twice
    Log.d("Upload Progress:",""+progress)
}

val call = service.createPost(requestBodyWithProgress)

Setup

Currently available via JitPack.

To use it, add the jitpack maven repository to your build.gradle file:

repositories {
  ...
  maven { url "https://jitpack.io" }
  ...
}

and add the dependency:

dependencies {
  ...
  implementation 'com.github.Musfick:retrofit-kotlin-upload-progress:0.1.0'
  ...
}

License

Copyright 2021 Musfick Jamil

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

๐Ÿ“š A android library for get upload progress from request body using retrofit. Support multiple file upload โฌ†.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages