更新记录

1.0.1(2021-01-26) 下载此版本

1、新增多文件同时切片 2、新增清空目录方法

1.0.0(2021-01-18) 下载此版本

大文件分片,适用于大文件分片上传,目前实现了分片功能,考虑到业务的不同,暂时未将上传开放


平台兼容性

Android Android CPU类型 iOS
适用版本区间:5.0 - 11.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


引入插件

const FileSpliter = uni.requireNativePlugin('Forke-FileSpliter');

使用插件


    1、设置保存路径
    let savePath = fs.root.fullPath;    

    2、选择文件,多文件的话
    plus.gallery.pick((files) => {
        files.files.map((path) => {
            that.spliter(path);
        });
    }, (e) => {
        console.log("取消选择图片");
    }, {
        filter: "none",
        multiple: true
    });

    3、开始切片
    plus.io.resolveLocalFileSystemURL(path, (entry) => {
        entry.file((file) => {
            FileSpliter.splitFile({
                filePath: file.fullPath,  //选择文件的完整路径,例如"/storage/0/..."
                savePath: savePath,  //保存文件的完整路径,需要该路径存在, 例如"/storage/0/..."
                fileName: file.name, //"文件名"  
                chunkSize: 1024 * 1024 * 10  //每一片的大小, 例如 1024 * 1024 * 10  代表10MB
            }, (ret) => {
                //成功的回调
                if (ret) {
                    if (ret.code == 'process') {
                        console.log("name", ret.name); //分片的所属文件名,用于区分多文件同时切片
                        console.log("chunk", ret.chunk); //分片序号
                        console.log("path", ret.path);  //分片的绝对路径
                    } else if (ret.code == 'complete') {
                        console.log("切片完成");
                    } else if (ret.code == 'start') {
                        console.log("切片开始");
                    }
                }
            }, (ret) => {
                //失败的回调
            });

        })
    })

    4、上传
    uni.uploadFile({
        url: url, //仅为示例,非真实的接口地址
        filePath: tempPath, //切片返回的路径
        name: 'files',
        header: {
            "Authorization": that.accessToken
        },
        formData: {
            "md5Hash": md5Hash, //分片的md5Hash
            "chunk": chunk,
            "chunkTotal": totalchunk, //这个需要自己根据文件总大小计算
            "fileName": fileName
        },
        success: (uploadFileRes) => {
            console.log(uploadFileRes.data);
        }
    });

    5、上传完成清空切片目录
    FileSpliter.clearFilePath({
                    savePath: savePath,
                    fileName: fileName
    }, (ret) => {
        if (ret) {
            if (ret.code == 'complete') {
                console.log("切片目录已清空");
            }
        }
    }, (ret) => {

    });

隐私、权限声明

1. 本插件需要申请的系统权限列表:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT License

Copyright (c) [2021]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问