100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Ionic中采用cordova-transfer上传图片到腾讯云对象存储(COS)

Ionic中采用cordova-transfer上传图片到腾讯云对象存储(COS)

时间:2024-06-02 03:26:42

相关推荐

Ionic中采用cordova-transfer上传图片到腾讯云对象存储(COS)

经过两周时间的折腾,终于实现了在Ionic中将图片上传到腾讯云COS中。这里记录一下自己踩过的坑。

在腾讯云COS提供的SDK包中,只有JavaScript-SDK包,该包的实现是采用Jquery实现的。而在我们Ionic开发中是采用Angular实现的,所以不太想引入Jquery的相关内容。所以想参考他的JavaScript-SDK的源码自己实现图片上传功能。

在JavaScript-SDK中文件的上传代码如下:

CosCloud.prototype.uploadFile = function (success, error, onprogress, bucketName, remotePath, file, insertOnly, taskReady) {var that = this;if (file.size > MAX_UNSLICE_FILE_SIZE) {that.sliceUploadFile(success, error, onprogress, bucketName, remotePath, file, insertOnly, undefined, undefined, taskReady);return;}if (remotePath.substr(remotePath.length - 1) === /) {error({code: -1, message: path not allow end with "/"});return;}remotePath = fixPath(remotePath);// 辅助 cancelTaskvar taskId = guid();var $xhr;var globalTask = {id: taskId,state: uploading,cancel: function () {$xhr && $xhr.abort();}};this.tasks[taskId] =

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。