android - 缺少api密钥android Cloudinary上传错误
问题描述
AndroidManifest.xml
<meta-data
android:name="CLOUDINARY_URL"
android:value="${cloudinaryUrl}" />
在我上传文件的活动中,我初始化了 MediaManager
MediaManager.init(this);
我已经使用它的uri上传了文件:
val requestId = MediaManager.get().upload(uri).callback(object : UploadCallback {
override fun onStart(requestId: String) {
// your code here
}
override fun onProgress(requestId: String, bytes: Long, totalBytes: Long) {
// example code starts here
val progress = bytes.toDouble() / totalBytes
// post progress to app UI (e.g. progress bar, notification)
// example code ends here
}
override fun onSuccess(requestId: String, resultData: Map<*, *>) {
// your code here
}
override fun onError(requestId: String, error: ErrorInfo) {
// your code here
}
override fun onReschedule(requestId: String, error: ErrorInfo) {
// your code here
}
}).dispatch()
问题是我得到了一个错误'Missing api key'
。我需要一个 api 密钥来进行未签名的上传吗?
解决方案
通过在文档中查看此处。在示例中,您需要通过SignatureProvider
示例代码:
Map config = new HashMap();
config.put("cloud_name", "myCloudName");
MediaManager.init(this, new SignatureProvider(){
@Override
public Signature provideSignature(Map options) {
// replace the following with a function that calls your backend signature generation endpoint
SignResult res = signUpload(options); // example name of a function that implements a synchronous HTTPS call
return new Signature(res.getSignature(), res.getApiKey(), res.getTimestamp());
}
@Override
public String getName() {
return "SampleSignatureProvider"; // for logging purposes
}
}, config);
要启用签名上传,您需要使用您的类实例的名称 (init(Context, SignatureProvider, Map)) 更新对 MediaManager 的 init 方法的调用。只要上传必须签名,您的课程就会被实施。
请参阅SignatureProvider接口
编辑
对于未签名的上传,您没有提到.unsigned("sample_preset")
. MediaManager.get().upload(uri)
有关更多信息,请参见此处
推荐阅读
- flutter - Flutter PageView 无法正常工作
- javascript - 如何使用 selenium 从 iframe 元素中获取标题?
- java - 如何在java中将地图转换为实体对象?
- sql - SQL如何仅在满足两个条件时排除行
- r - 谁能帮我在不使用日期格式的情况下将我的数据框转换为时间序列对象?
- flutter - Flutter JWT 令牌自动刷新
- mysql - 为了工作,我的 CREATE TABLE 中缺少什么?mysql 8.X
- html - HTML/CSS 将图标放在密码输入字段中
- github - GitHub 组织从一家公司转移到另一家拥有所有存储库的公司
- node.js - 向 Socket.io 中的其他房间发送消息