diff --git a/android/src/main/java/video/api/reactnative/uploader/UploaderModule.kt b/android/src/main/java/video/api/reactnative/uploader/UploaderModule.kt index 5c9db6a..6fc0b74 100644 --- a/android/src/main/java/video/api/reactnative/uploader/UploaderModule.kt +++ b/android/src/main/java/video/api/reactnative/uploader/UploaderModule.kt @@ -88,6 +88,56 @@ class UploaderModule(reactContext: ReactApplicationContext) : } } + // Progressive upload + @ReactMethod + override fun createProgressiveUploadSession(sessionId: String, videoId: String) { + uploaderModuleImpl.createUploadProgressiveSession(sessionId, videoId) + } + + @ReactMethod + override fun createProgressiveUploadWithUploadTokenSession( + sessionId: String, + token: String, + videoId: String? + ) { + uploaderModuleImpl.createUploadWithUploadTokenProgressiveSession(sessionId, token, videoId) + } + + @ReactMethod + override fun uploadPart(sessionId: String, filePath: String, promise: Promise) { + uploadPart(sessionId, filePath, false, promise) + } + + @ReactMethod + override fun uploadLastPart(sessionId: String, filePath: String, promise: Promise) { + uploadPart(sessionId, filePath, true, promise) + } + + @ReactMethod + override fun disposeProgressiveUploadSession(sessionId: String) { + uploaderModuleImpl.disposeProgressiveUploadSession(sessionId) + } + + private fun uploadPart( + sessionId: String, + filePath: String, + isLastPart: Boolean, + promise: Promise + ) { + try { + uploaderModuleImpl.uploadPart(sessionId, filePath, isLastPart, { _ -> + }, { video -> + promise.resolve(video) + }, { + promise.reject(CancellationException("Upload was cancelled")) + }, { e -> + promise.reject(e) + }) + } catch (e: Exception) { + promise.reject(e) + } + } + companion object { const val NAME = "ApiVideoUploader" diff --git a/android/src/oldarch/video/api/reactnative/uploader/UploaderModule.kt b/android/src/oldarch/video/api/reactnative/uploader/UploaderModule.kt index f24d0ea..2e45f28 100644 --- a/android/src/oldarch/video/api/reactnative/uploader/UploaderModule.kt +++ b/android/src/oldarch/video/api/reactnative/uploader/UploaderModule.kt @@ -20,4 +20,14 @@ abstract class UploaderModuleSpec(reactContext: ReactApplicationContext) : abstract fun uploadWithUploadToken(token: String, filePath: String, videoId: String?, promise: Promise) abstract fun upload(videoId: String, filePath: String, promise: Promise) + + abstract fun createProgressiveUploadSession(sessionId: String, videoId: String) + + abstract fun createProgressiveUploadWithUploadTokenSession(sessionId: String, token: String, videoId: String?) + + abstract fun uploadPart(sessionId: String, filePath: String, promise: Promise) + + abstract fun uploadLastPart(sessionId: String, filePath: String, promise: Promise) + + abstract fun disposeProgressiveUploadSession(sessionId: String) }