以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]腾讯云的回调函数如何接受? 已解决! (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=191208) |
|
-- 作者:cbt -- 发布时间:2024/4/1 17:48:00 -- [求助]腾讯云的回调函数如何接受? 已解决! vb.net 代码如下: uploadTask.progressCallback = delegate (long completed, long total) { Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)); }; 不明白这个如何接收. 正确代码: Dim progress As cosxml.Callback.OnProgressCallback = Function(completed , total) Output.Show( completed & " " & total) End Function uploadTask.progressCallback = progress [此贴子已经被作者于2024/4/2 15:36:40编辑过]
|
|
-- 作者:有点蓝 -- 发布时间:2024/4/1 20:26:00 -- 接口文档链接发过来看看 |
|
-- 作者:cbt -- 发布时间:2024/4/2 9:06:00 -- using COSXML.Model.Object; using COSXML.Auth; using COSXML.Transfer; using System; using COSXML; using System.Threading.Tasks; namespace COSSnippet { public class TransferUploadObjectModel { private CosXml cosXml; TransferUploadObjectModel() { CosXmlConfig config = new CosXmlConfig.Builder() .SetRegion("COS_REGION") // 设置默认的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224 .Build(); string secretId = "SECRET_ID"; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi string secretKey = "SECRET_KEY"; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi long durationSecond = 600; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); this.cosXml = new CosXmlServer(config, qCloudCredentialProvider); } /// 高级接口上传文件 public async Task TransferUploadFile() { // 初始化 TransferConfig TransferConfig transferConfig = new TransferConfig(); // 手动设置开始分块上传的大小阈值为10MB,默认值为5MB transferConfig.DivisionForUpload = 10 * 1024 * 1024; // 手动设置分块上传中每个分块的大小为2MB,默认值为1MB transferConfig.SliceSizeForUpload = 2 * 1024 * 1024; // 初始化 TransferManager TransferManager transferManager = new TransferManager(cosXml, transferConfig); // 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer String bucket = "examplebucket-1250000000"; String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即称对象键 String srcPath = @"temp-source-file";//本地文件绝对路径 // 上传对象 COSXMLUploadTask uploadTask = new COSXMLUploadTask(bucket, cosPath); uploadTask.SetSrcPath(srcPath); uploadTask.progressCallback = delegate (long completed, long total) { Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)); }; try { COSXML.Transfer.COSXMLUploadTask.UploadTaskResult result = await transferManager.UploadAsync(uploadTask); Console.WriteLine(result.GetResultInfo()); string eTag = result.eTag; } catch (Exception e) { Console.WriteLine("CosException: " + e); } } static void Main(string[] args) { TransferUploadObjectModel m = new TransferUploadObjectModel(); /// 高级接口上传对象 m.TransferUploadFile().Wait(); // .cssg-methods-pragma } } } [此贴子已经被作者于2024/4/2 9:05:57编辑过]
|
|
-- 作者:有点蓝 -- 发布时间:2024/4/2 9:29:00 -- uploadTask.progressCallback = Function(ByVal completed As Long, ByVal total As Long) Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)) End Function
|
|
-- 作者:cbt -- 发布时间:2024/4/2 10:42:00 -- 加上后,报这个错误,我该如何修改? .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2022.8.18.1 错误所在事件:自定义函数,cos_文件_上传 详细错误信息: 调用的目标发生了异常。 从类型“VB$AnonymousDelegate_0(Of Long,Long,Object)”到类型“OnProgressCallback”的转换无效。
|
|
-- 作者:有点蓝 -- 发布时间:2024/4/2 11:11:00 -- 试试 Dim progress As OnProgressCallback = Function(completed , total) Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)) uploadTask.progressCallback = progress 或者 uploadTask.progressCallback == Function(completed , total) Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total))
|
|
-- 作者:cbt -- 发布时间:2024/4/2 15:37:00 -- 以下是引用有点蓝在2024/4/2 11:11:00的发言:
试试 Dim progress As OnProgressCallback = Function(completed , total) Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)) uploadTask.progressCallback = progress 或者 uploadTask.progressCallback == Function(completed , total) Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total))
|