Skip to content

A Multipart upload solution on Android, including notification and network change.

License

Notifications You must be signed in to change notification settings

CTKnight/UploadManager

Repository files navigation

UploadManager (Alpha)

CircleCI

A Multipart upload solution on Android, including progress notification and network change. This is a project based on AOSP DownloadManager and I made this with kotlin and OkHttp3.


Usage

  • get a instance of UploadManager
    val uploadManager: UploadManager = UploadManager.getUploadManger(context)
    // init it when your app boots
    uploadManager.init()

The best practise is to call UploadManager.init() as early as you need to display notifications related to upload tasks and to clear/resume the crashed tasks

  • upload
    val uri = Uri.parse(info.fileUri)

    val fileHeaders = mutableMapOf(Pair("User-Agent", "Box Android")).toHeaders()
    // dsl for building request    
    val request = request {
      targetUrl = UPLOAD_URI.toString().toHttpUrl()
      parts{
        +Part("filecount", "1")
        +Part("predefine", "1")
        +Part("token", info.code)
        +Part("secret", info.password)
        +Part("expiration", Expiration.toSeconds(info.expireTimeOption!!).toString())
        +Part("file", fileInfo =  FileInfo(uri, (info.mimeType
            ?: "application/octet-stream").toMediaTypeOrNull(), info.fileName))
      }
      headers= fileHeaders
    }

    uploadManage.enqueue(request.build())
  • cancel a upload task
    uploadManger.cancel(uploadId)
  • restart a upload task
    uploadManger.restartUpload(uploadId)
  • query a upload task

TODO


Proguard

This project already add consumerProguardFiles, so feel free to use proguard.

How to install

For now, you have to download source and install it to local maven. I will publish it to online repo soon.

  1. clone this repo and run gradlew lib:install this will install the UploadManager library to your local maven repo (in ~/.m2)

  2. edit yourProject/app/build.gradle

    add

    repositories {
        google()
        jcenter()
        mavenLocal()
    }

    and

    dependencies {
        implementation 'me.ctknight.uploadmanager:lib:$latest-version'
    }

    be sure to replace the $latest-version with correct version number

License

Copyright 2018 Lai Jiewen.

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.

see also: LICENSE file

Reference

  • AOSP DownloadProvider AOSP license

  • OkHttp

    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 Multipart upload solution on Android, including notification and network change.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages