0
0

More than 3 years have passed since last update.

Drive KitでHUAWEI Driveからファイルをダウンロードする方法

Posted at

HUAWEI Driveからのダウンロード手順

  1. HUAWEI Driveに接続する
  2. ファイルオブジェクトを取得する
  3. HUAWEI Driveのダウンロードリクエストを実行する

注意点
1. ファイルサイズが20MB以下の場合、isDirectDownloadEnabledをtrueに設定できます。

サンプル

private var drive: Drive? = null

fun load(filename: String, dest: File, isApplicationData: Boolean) {
    getFile(filename, false, isApplicationData)?.let { file ->
        download(file, dest)
    }
}

private fun download(file: com.huawei.cloud.services.drive.model.File, dest: File) {
    drive?.let { drive ->
        val size: Long = file.getSize()
        val isDirectDownload = file.getSize() < DIRECT_DOWNLOAD_MAX_SIZE
        drive.files()[file.id].let { get ->
            get.mediaHttpDownloader.setContentRange(0, size - 1).isDirectDownloadEnabled = isDirectDownload
            get.executeContentAndDownloadTo(FileOutputStream(dest))
        }
    }
}

GitHub

HMS Drive Kit Demo : https://github.com/Rei2020GitHub/MyPublicProject/tree/master/DriveKitDemo

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0