pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    1. <small id='32v6s'></small><noframes id='32v6s'>

      <legend id='32v6s'><style id='32v6s'><dir id='32v6s'><q id='32v6s'></q></dir></style></legend>
        <bdo id='32v6s'></bdo><ul id='32v6s'></ul>

      <i id='32v6s'><tr id='32v6s'><dt id='32v6s'><q id='32v6s'><span id='32v6s'><b id='32v6s'><form id='32v6s'><ins id='32v6s'></ins><ul id='32v6s'></ul><sub id='32v6s'></sub></form><legend id='32v6s'></legend><bdo id='32v6s'><pre id='32v6s'><center id='32v6s'></center></pre></bdo></b><th id='32v6s'></th></span></q></dt></tr></i><div class="jjciwuo" id='32v6s'><tfoot id='32v6s'></tfoot><dl id='32v6s'><fieldset id='32v6s'></fieldset></dl></div>
      <tfoot id='32v6s'></tfoot>
    2. XMLHttpRequest:以 XML 和圖像作為有效負載的多部分

      XMLHttpRequest: Multipart/Related POST with XML and image as payload(XMLHttpRequest:以 XML 和圖像作為有效負載的多部分/相關 POST)

      • <tfoot id='fT0qj'></tfoot>

          <legend id='fT0qj'><style id='fT0qj'><dir id='fT0qj'><q id='fT0qj'></q></dir></style></legend>

            <small id='fT0qj'></small><noframes id='fT0qj'>

              <tbody id='fT0qj'></tbody>
              <i id='fT0qj'><tr id='fT0qj'><dt id='fT0qj'><q id='fT0qj'><span id='fT0qj'><b id='fT0qj'><form id='fT0qj'><ins id='fT0qj'></ins><ul id='fT0qj'></ul><sub id='fT0qj'></sub></form><legend id='fT0qj'></legend><bdo id='fT0qj'><pre id='fT0qj'><center id='fT0qj'></center></pre></bdo></b><th id='fT0qj'></th></span></q></dt></tr></i><div class="2dcsdfz" id='fT0qj'><tfoot id='fT0qj'></tfoot><dl id='fT0qj'><fieldset id='fT0qj'></fieldset></dl></div>

              • <bdo id='fT0qj'></bdo><ul id='fT0qj'></ul>

                本文介紹了XMLHttpRequest:以 XML 和圖像作為有效負載的多部分/相關 POST的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試從 Chrome 擴展程序中將圖像(帶有元數據)發布到 Picasa 網絡相冊.請注意,正如我在此處所述,使用 Content-Type image/xyz 的常規帖子有效.但是,我希望包含描述/關鍵字和 協議規范 描述了 multipart/related 格式 帶有 XML 和數據部分.

                I'm trying to POST an image (with Metadata) to Picasa Webalbums from within a Chrome-Extension. Note that a regular post with Content-Type image/xyz works, as I described here. However, I wish to include a description/keywords and the protocol specification describes a multipart/related format with a XML and data part.

                我通過 HTML5 FileReader 和用戶文件輸入獲取數據.我檢索一個二進制文件使用

                I'm getting the Data through HTML5 FileReader and user file input. I retrieve a binary String using

                FileReader.readAsBinaryString(file);
                

                假設這是我在 FileReader 加載字符串后的回調代碼:

                Assume this is my callback code once the FileReader has loaded the string:

                function upload_to_album(binaryString, filetype, albumid) {
                
                    var method = 'POST';
                    var url = 'http://picasaweb.google.com/data/feed/api/user/default/albumid/' + albumid;
                    var request = gen_multipart('Title', 'Description', binaryString, filetype);
                    var xhr = new XMLHttpRequest();
                    xhr.open(method, url, true);
                    xhr.setRequestHeader("GData-Version", '3.0');
                    xhr.setRequestHeader("Content-Type",  'multipart/related; boundary="END_OF_PART"');
                    xhr.setRequestHeader("MIME-version", "1.0");
                    // Add OAuth Token
                    xhr.setRequestHeader("Authorization", oauth.getAuthorizationHeader(url, method, ''));
                    xhr.onreadystatechange = function(data) {
                        if (xhr.readyState == 4) {
                            // .. handle response
                        }
                    };
                    xhr.send(request);
                }   
                

                gen_multipart 函數只是從輸入值和 XML 模板生成多部分,并產生完全相同的輸出 作為規范(除了..二進制圖像數據..),但為了完整起見,這里是:

                The gen_multipart function just generates the multipart from the input values and the XML template and produces the exact same output as the specification (apart from ..binary image data..), but for sake of completeness, here it is:

                function gen_multipart(title, description, image, mimetype) {
                    var multipart = ['Media multipart posting', "   
                ", '--END_OF_PART', "
                ",
                    'Content-Type: application/atom+xml',"
                ","
                ",
                    "<entry xmlns='http://www.w3.org/2005/Atom'>", '<title>', title, '</title>',
                    '<summary>', description, '</summary>',
                    '<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo" />',
                    '</entry>', "
                ", '--END_OF_PART', "
                ",
                    'Content-Type:', mimetype, "
                
                ",
                    image, "
                ", '--END_OF_PART--'];
                    return multipart.join("");
                }
                

                問題是,POST 有效負載與原始圖像數據不同,因此會導致錯誤請求(Picasa 不會接受圖像),盡管在使用時它工作正常

                The problem is, that the POST payload differs from the raw image data, and thus leads to a Bad Request (Picasa won't accept the image), although it worked fine when using

                xhr.send(file) // With content-type set to file.type
                

                我的問題是,如何讓 real 二進制圖像包含在多部分中?我認為它只是通過將它附加到 xml 字符串而被破壞,但我似乎無法修復它.

                My question is, how do I get the real binary image to include it in the multipart? I assume it is mangled by just appending it to the xml string, but I can't seem to get it fixed.

                請注意,由于 Picasa 中存在 舊錯誤,base64 不是解決方案.

                Note that due to an old bug in Picasa, base64 is not the solution.

                推薦答案

                XMLHttpRequest 規范 聲明使用 .send() 方法發送的數據將轉換為 unicode,并編碼為 UTF-8.

                The XMLHttpRequest specification states that the data send using the .send() method is converted to unicode, and encoded as UTF-8.

                推薦的二進制數據上傳方式是通過FormData API.但是,由于您不只是上傳文件,而是將二進制數據包裝在 XML 中,因此此選項沒有用.

                The recommended way to upload binary data is through FormData API. However, since you're not just uploading a file, but wrapping the binary data within XML, this option is not useful.

                解決方案可以在的源代碼中找到FormData for Web Workers Polyfill,這是我遇到類似問題時寫的.為了防止 Unicode 轉換,所有數據都添加到一個數組中,最后作為 傳輸數組緩沖區.根據規范,字節序列在傳輸時不會被觸及.

                The solution can be found in the source code of the FormData for Web Workers Polyfill, which I've written when I encountered a similar problem. To prevent the Unicode-conversion, all data is added to an array, and finally transmitted as an ArrayBuffer. The byte sequences are not touched on transmission, per specification.

                以下代碼是基于 的特定衍生代碼Web Workers Polyfill 的 FormData:

                function gen_multipart(title, description, image, mimetype) {
                    var multipart = [ "..." ].join(''); // See question for the source
                    var uint8array = new Uint8Array(multipart.length);
                    for (var i=0; i<multipart.length; i++) {
                        uint8array[i] = multipart.charCodeAt(i) & 0xff;
                    }
                    return uint8array.buffer; // <-- This is an ArrayBuffer object!
                }
                

                當您使用 .readAsArrayBuffer 而不是 .readAsBinaryString:

                function gen_multipart(title, description, image, mimetype) {
                    image = new Uint8Array(image); // Wrap in view to get data
                
                    var before = ['Media ... ', 'Content-Type:', mimetype, "
                
                "].join('');
                    var after = '
                --END_OF_PART--';
                    var size = before.length + image.byteLength + after.length;
                    var uint8array = new Uint8Array(size);
                    var i = 0;
                
                    // Append the string.
                    for (; i<before.length; i++) {
                        uint8array[i] = before.charCodeAt(i) & 0xff;
                    }
                
                    // Append the binary data.
                    for (var j=0; j<image.byteLength; i++, j++) {
                        uint8array[i] = image[j];
                    }
                
                    // Append the remaining string
                    for (var j=0; j<after.length; i++, j++) {
                        uint8array[i] = after.charCodeAt(j) & 0xff;
                    }
                    return uint8array.buffer; // <-- This is an ArrayBuffer object!
                }
                

                這篇關于XMLHttpRequest:以 XML 和圖像作為有效負載的多部分/相關 POST的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)

                  <tbody id='cwIdH'></tbody>

                    <legend id='cwIdH'><style id='cwIdH'><dir id='cwIdH'><q id='cwIdH'></q></dir></style></legend>
                  1. <i id='cwIdH'><tr id='cwIdH'><dt id='cwIdH'><q id='cwIdH'><span id='cwIdH'><b id='cwIdH'><form id='cwIdH'><ins id='cwIdH'></ins><ul id='cwIdH'></ul><sub id='cwIdH'></sub></form><legend id='cwIdH'></legend><bdo id='cwIdH'><pre id='cwIdH'><center id='cwIdH'></center></pre></bdo></b><th id='cwIdH'></th></span></q></dt></tr></i><div class="n7lyb22" id='cwIdH'><tfoot id='cwIdH'></tfoot><dl id='cwIdH'><fieldset id='cwIdH'></fieldset></dl></div>
                    • <bdo id='cwIdH'></bdo><ul id='cwIdH'></ul>
                          <tfoot id='cwIdH'></tfoot>

                          <small id='cwIdH'></small><noframes id='cwIdH'>

                          主站蜘蛛池模板: 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 超声波破碎仪-均质乳化机(供应杭州,上海,北京,广州,深圳,成都等地)-上海沪析实业有限公司 | 专业的压球机生产线及解决方案厂家-河南腾达机械厂 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 | 成都离婚律师|成都结婚律师|成都离婚财产分割律师|成都律师-成都离婚律师网 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | 铁艺,仿竹,竹节,护栏,围栏,篱笆,栅栏,栏杆,护栏网,网围栏,厂家 - 河北稳重金属丝网制品有限公司 山东太阳能路灯厂家-庭院灯生产厂家-济南晟启灯饰有限公司 | 生产加气砖设备厂家很多,杜甫机械加气砖设备价格公道 | R507制冷剂,R22/R152a制冷剂厂家-浙江瀚凯制冷科技有限公司 | 台式低速离心机-脱泡离心机-菌种摇床-常州市万丰仪器制造有限公司 | 品牌设计_VI设计_电影海报设计_包装设计_LOGO设计-Bacross新越品牌顾问 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 执业药师报名条件,考试时间,考试真题,报名入口—首页 | 手术室净化厂家_成都实验室装修公司_无尘车间施工单位_洁净室工程建设团队-四川华锐16年行业经验 | 塑料检查井_双扣聚氯乙烯增强管_双壁波纹管-河南中盈塑料制品有限公司 | 缠绕机|缠绕膜包装机|缠绕包装机-上海晏陵智能设备有限公司 | 济南律师,济南法律咨询,山东法律顾问-山东沃德律师事务所 | 粘弹体防腐胶带,聚丙烯防腐胶带-全民塑胶| 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | 偏心半球阀-电动偏心半球阀-调流调压阀-旋球阀-上欧阀门有限公司 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 三效蒸发器_多效蒸发器价格_四效三效蒸发器厂家-青岛康景辉 | 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 挖掘机挖斗和铲斗生产厂家选择徐州崛起机械制造有限公司 | 合肥弱电工程_安徽安防工程_智能化工程公司-合肥雷润 | 爱德华真空泵油/罗茨泵维修,爱发科-比其尔产品供应东莞/杭州/上海等全国各地 | 高压微雾加湿器_工业加湿器_温室喷雾-昌润空气净化设备 | 炭黑吸油计_测试仪,单颗粒子硬度仪_ASTM标准炭黑自销-上海贺纳斯仪器仪表有限公司(HITEC中国办事处) | 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 | 软文发布-新闻发布推广平台-代写文章-网络广告营销-自助发稿公司媒介星 | 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 悬浮拼装地板_幼儿园_篮球场_悬浮拼接地板-山东悬浮拼装地板厂家 | 电缆桥架生产厂家_槽式/梯式_热镀锌线槽_广东东莞雷正电气 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 阳光1号桔柚_无核沃柑_柑橘新品种枝条苗木批发 - 苧金网 | 数显水浴恒温振荡器-分液漏斗萃取振荡器-常州市凯航仪器有限公司 | 热处理炉-退火炉-回火炉设备厂家-丹阳市电炉厂有限公司 |