Skip to content

Commit

Permalink
feat(android): add API for progressive upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Mar 28, 2024
1 parent 6a03ec0 commit d2d7ce0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit d2d7ce0

Please sign in to comment.