Skip to content

Commit 5e95593

Browse files
authored
feat: add support of ktor_version 3.1.3 (#31)
* feat: add support of ktor_version 3.1.3 * Update FileDownloader.kt
1 parent 6332025 commit 5e95593

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

android/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ dependencies {
138138
implementation project(":react-native-nitro-modules")
139139

140140
// Add a dependency on NitroFS
141-
implementation("io.ktor:ktor-client-core:2.3.2")
142-
implementation("io.ktor:ktor-client-okhttp:2.3.2")
141+
var ktor_version = "3.1.3"
142+
implementation("io.ktor:ktor-client-core:$ktor_version")
143+
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
143144
}
144145

145146
if (isNewArchitectureEnabled()) {

android/src/main/java/com/nitrofs/FileDownloader.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class FileDownloader {
2727
client.use { it
2828
it.prepareGet("$serverUrl/$fileName") {
2929
method = HttpMethod.Get
30-
onDownload { bytesSentTotal, contentLength ->
31-
if (bytesSentTotal > 0){
30+
onDownload { totalBytesSent, contentLength ->
31+
if (totalBytesSent > 0 && contentLength != null){
3232
onProgress?.let {
3333
Handler(Looper.getMainLooper()).post {
34-
onProgress.invoke(bytesSentTotal.toDouble(), contentLength.toDouble())
34+
onProgress.invoke(totalBytesSent.toDouble(), contentLength.toDouble())
3535
}
3636
}
3737
}

android/src/main/java/com/nitrofs/NitroFileUploader.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package com.nitrofs
22

33
import android.os.Handler
44
import android.os.Looper
5+
import io.ktor.client.HttpClient
56
import com.margelo.nitro.nitrofs.NitroUploadMethod
67
import com.margelo.nitro.nitrofs.NitroUploadOptions
7-
import io.ktor.client.HttpClient
88
import io.ktor.client.engine.okhttp.OkHttp
99
import io.ktor.client.plugins.onUpload
1010
import io.ktor.client.request.forms.formData
@@ -42,10 +42,12 @@ class NitroFileUploader {
4242
}
4343
){
4444
method = getMethod(uploadOptions.method)
45-
onUpload { bytesSent, totalBytes ->
46-
onProgress?.let {
47-
Handler(Looper.getMainLooper()).post {
48-
it.invoke(bytesSent.toDouble(), totalBytes.toDouble())
45+
onUpload { totalBytesSent, totalBytes ->
46+
if (totalBytesSent > 0 && totalBytes != null) {
47+
onProgress?.let {
48+
Handler(Looper.getMainLooper()).post {
49+
it.invoke(totalBytesSent.toDouble(), totalBytes.toDouble())
50+
}
4951
}
5052
}
5153
}

0 commit comments

Comments
 (0)