科技知识动态:javascript - 上传失败 token not specified

导读 跟大家讲解下有关javascript - 上传失败 token not specified,相信小伙伴们对这个话题应该也很关注吧,现在就为小伙伴们说说javascri

跟大家讲解下有关javascript - 上传失败 token not specified,相信小伙伴们对这个话题应该也很关注吧,现在就为小伙伴们说说javascript - 上传失败 token not specified,小编也收集到了有关javascript - 上传失败 token not specified的相关资料,希望大家看到了会喜欢。

同样的代码在www.a.com 下上传正常在www.b.com 下,相同的代码,通过www.a.com 拿到token 上传报错 error:"token not specified

uptoken_func 下uptoken 返回了空值之后才被 ajax 回调过来的数据赋值,所以上传的时候 token 为空

var qiniu_up = qiniu.uploader({ runtimes : 'html5,flash,html4', browse_button : 'qiniu_browse', get_new_uptoken: true, unique_names: false, save_key : true, domain : '', container : 'container', max_file_size: '4mb', flash_swf_url : '', silverlight_xap_url : '', max_retries: 1, dragdrop: false, drop_element : 'container', chunk_size : '4mb', auto_start: false, multi_selection: false, filters : { mime_types : [{title : 'Image files', extensions : 'jpg,jpeg,gif,png,bmp'},{title : 'Voice files', extensions : 'mp3,wav'}] }, init : { }, uptoken_func: function(file){ var uptoken = ''; var media_info = '[{"directory":"1","directory_class":"","up_file_name":"'+file.name+'","media_type":"1"}]'; $.ajax({ type :"post", async : false, url : '', data : { app_version : '1.0', app_target : 3, sdk_version : '1.0', plat : 'other', media_info : media_info }, dataType :"jsonp", jsonp:"jsonpCallback", success : function(data){ if(data.code == '1') { var list = data.data.uptoken_list; uptoken = list[0]['uptoken']; media_id = list[0]['media_id']; } else { alert(data.message); } }, error : function(XMLHttpRequest, textStatus, errorThrown){ } }); return uptoken; } });

回复内容:

同样的代码在www.a.com 下上传正常在www.b.com 下,相同的代码,通过www.a.com 拿到token 上传报错 error:"token not specified

uptoken_func 下uptoken 返回了空值之后才被 ajax 回调过来的数据赋值,所以上传的时候 token 为空

var qiniu_up = qiniu.uploader({ runtimes : 'html5,flash,html4', browse_button : 'qiniu_browse', get_new_uptoken: true, unique_names: false, save_key : true, domain : '', container : 'container', max_file_size: '4mb', flash_swf_url : '', silverlight_xap_url : '', max_retries: 1, dragdrop: false, drop_element : 'container', chunk_size : '4mb', auto_start: false, multi_selection: false, filters : { mime_types : [{title : 'Image files', extensions : 'jpg,jpeg,gif,png,bmp'},{title : 'Voice files', extensions : 'mp3,wav'}] }, init : { }, uptoken_func: function(file){ var uptoken = ''; var media_info = '[{"directory":"1","directory_class":"","up_file_name":"'+file.name+'","media_type":"1"}]'; $.ajax({ type :"post", async : false, url : '', data : { app_version : '1.0', app_target : 3, sdk_version : '1.0', plat : 'other', media_info : media_info }, dataType :"jsonp", jsonp:"jsonpCallback", success : function(data){ if(data.code == '1') { var list = data.data.uptoken_list; uptoken = list[0]['uptoken']; media_id = list[0]['media_id']; } else { alert(data.message); } }, error : function(XMLHttpRequest, textStatus, errorThrown){ } }); return uptoken; } });

看楼主的代码 好像是往七牛CDN上面上传文件token的问题 楼主可以看看是不是JS跨域问题 你也可以看看七牛的开发文档 或者 联系七牛的技术人员联调一下

uptoken_func 下的ajax 跨域了以后他的运行顺序变了 所有的程序都执行完了才执行到success 下的uptoken 的被赋值,所以上传上去的uptoken 为空

来源:php中文网

免责声明:本文由用户上传,如有侵权请联系删除!