在Kotlin中实现Cloudinary Signed Upload

问题描述 投票:1回答:1

我正在使用Kotlin实施签名上传到Cloudinary的艰难时期。我已经实现了我的后端,为我提供了一个signture和时间戳。这是我为构建配置所做的:

var config = HashMap<String, Any> ()
        config.put("cloud_name", "my_cloud_name");
        //config.put("apiKey", my_api_key);
        config.put("use_filename", true);

现在,我无法使用签名执行MediaManager.init。有人可以帮忙吗? Java代码说要执行以下操作,但我无法在Kotlin中重现相同的内容:

MediaManager.init(this, new SignatureProvider() {
    @Override
    public Signature provideSignature(Map options) {
        // call server signature endpoint
    }
}, null);
kotlin cloudinary
1个回答
0
投票

这是在Kotlin中使用签名提供程序初始化媒体管理器的方法:

MediaManager.init(thiscontext!!, object: SignatureProvider {
        override fun provideSignature(options: MutableMap<Any?, Any?>?): Signature {
            return myBackendConnector.signRequest(options)
        }

        override fun getName(): String {
            return "myCustomSignatureProvider"
        }

    }, config)

这将起作用,假设你的后端已经有api键(它应该),并且连接器的返回类型是Signature。否则,您需要将后端的结果调整为Signature(使用服务器提供的结果填充POJO)。

© www.soinside.com 2019 - 2024. All rights reserved.