javascript - 上傳失敗 token not specified

來源:互聯網
上載者:User
同樣的代碼
在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 為空白

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.