关于H5使用web直传失败的问题求助
回 1楼shinenuaa的帖子
你好,代码如下,运行ios模拟器时将 client.multipartUpload上传请求直接跳过,改去执行catch
var uploadFile = function (client) {
var file = document.getElementById('publishFile').files[0];
console.log('---------'+file);
console.log('token--------------' + token);
console.log(file.name + ' => ' + key);
var body = 'token=' + token + '&infoId=' + $rootScope.infoId + '&type=2&imageUrls=http://bucket名字.oss-cn-shanghai.aliyuncs.com/' + key;
var contentLength = body.length;
console.log('body ========' + body);
console.log('bodyLength = ' + contentLength);
return client.multipartUpload(key, file, {
//progress: progress,
headers: {
'x-oss-callback': encodeCallback({
url: 'http://服务器地址/oss/callback',
//query: {user: 'js-sdk'},
//contentType: 'application/json',
body: body,
contentLength: contentLength
}),
'Access-Control-Allow-Origin' : '*'
}
}).then(function (res) {
console.log('upload success: %j', res);
console.log(res.data);
$ionicLoading.hide();
if (res.data.code == 0) {
UtilsService.alertShowOne('操作成功,前往首页', function () {
$state.go('tab.homePage');
});
} else {
UtilsService.alertShowOne('信息发布成功,上传失败图片无法显示',function(){
var token = localStorage.getItem('token');
var data = {
infoId:$rootScope.infoId,
token:token
};
RequestService.request(mConfig.updateInfoImg_url,data).then(function(value){
console.log('updateInfoImg_url成功');
$state.go('tab.homePage');
});
});
}
var uploadFile = function (client) {
var file = document.getElementById('publishFile').files[0];
console.log('---------'+file);
console.log('token--------------' + token);
console.log(file.name + ' => ' + key);
var body = 'token=' + token + '&infoId=' + $rootScope.infoId + '&type=2&imageUrls=http://bucket名字.oss-cn-shanghai.aliyuncs.com/' + key;
var contentLength = body.length;
console.log('body ========' + body);
console.log('bodyLength = ' + contentLength);
return client.multipartUpload(key, file, {
//progress: progress,
headers: {
'x-oss-callback': encodeCallback({
url: 'http://服务器IP地址/oss/callback',
//query: {user: 'js-sdk'},
//contentType: 'application/json',
body: body,
contentLength: contentLength
}),
'Access-Control-Allow-Origin' : '*'
}
}).then(function (res) {
console.log('upload success: %j', res);
console.log(res.data);
$ionicLoading.hide();
if (res.data.code == 0) {
UtilsService.alertShowOne('操作成功,前往首页', function () {
$state.go('tab.homePage');
});
} else {
UtilsService.alertShowOne('信息发布成功,上传失败图片无法显示',function(){
var token = localStorage.getItem('token');
var data = {
infoId:$rootScope.infoId,
token:token
};
RequestService.request(mConfig.updateInfoImg_url,data).then(function(value){
console.log('updateInfoImg_url成功');
$state.go('tab.homePage');
});
});
};
赞0
踩0