args[0] isn’t a typed array or an array buffer
-
Creator 版本: 2.4.3
-
目标平台: ios
-
重现方式:使用cocos ios端调用腾讯云存储桶cos上传文件
utf2buffer(utfstr) {
var buf = new ArrayBuffer(utfstr.length);
var bufView = new Uint8Array(buf);
for (var i = 0, strlen = utfstr.length; i < strlen; i++) {
bufView[i] = utfstr.charCodeAt(i);
}
return buf;
},
let buf = this.utf2buffer(fileObjectStr)
this.curCos.putObject({
Bucket: Bucket, /* 必须 */
Region: Region, /* 存储桶所在地域,必须字段 */
Key: filePath, /* 必须 */
StorageClass: 'STANDARD', //标准存储
Body: buf, // 上传文件对象
// ContentLength: len,
onProgress: function (progressData) {
console.log(JSON.stringify(progressData));
if (progressData.percent == 1) {
if (cb) {
cb()
}
}
}
}, function (err, data) {
console.log(err || data);
if (err) {
g_systemTip_Id(10040084)
}
});
-
首个报错:

-
手机型号: iphonexr 或者ipad
-
编辑器操作系统: xcode
-
重现概率: 100%
这个问题研究了2个礼拜 最后发现无论我在存储桶传string arraybuffer 还是Blob
最终存储桶都会转换成Blob去send
但是cocos底层又不支持Blob
腾讯云存储桶代码
var getFileSize = function (api, params, callback) {
var size;
if (typeof params.Body === 'string') {
params.Body = new Blob([params.Body], {type: 'text/plain'});
} else if (params.Body instanceof ArrayBuffer) {
params.Body = new Blob([params.Body]);
}
if ((params.Body && (params.Body instanceof Blob || params.Body.toString() === '[object File]' || params.Body.toString() === '[object Blob]'))) {
size = params.Body.size;
} else {
callback(util.error(new Error('params body format error, Only allow File|Blob|String.')));
return;
}
params.ContentLength = size;
callback(null, size);
};
最终腾讯云存储桶到了send前
// send
xhr.send(opt.body || '');
这个body发的都是Blob
而我总不能去改腾讯SDK吧
请教有没有什么办法可以让http支持发送Blob
腾讯云存储桶连接
https://cloud.tencent.com/document/product/436/11459
相关代码
上传对象
简单上传接口适用于小文件上传,大文件请使用分块上传接口,详情请参见 对象操作 文档。
cos.putObject({
Bucket: 'examplebucket-1250000000', /* 必须 */
Region: 'COS_REGION', /* 存储桶所在地域,必须字段 */
Key: 'exampleobject', /* 必须 */
StorageClass: 'STANDARD',
Body: fileObject, // 上传文件对象
onProgress: function(progressData) {
console.log(JSON.stringify(progressData));
}
}, function(err, data) {
console.log(err || data);
});
