久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    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="qwawimqqmiuu" id='32v6s'><tfoot id='32v6s'></tfoot><dl id='32v6s'><fieldset id='32v6s'></fieldset></dl></div>
      <tfoot id='32v6s'></tfoot>
    2. XMLHttpRequest:以 XML 和圖像作為有效負(fù)載的多部分

      XMLHttpRequest: Multipart/Related POST with XML and image as payload(XMLHttpRequest:以 XML 和圖像作為有效負(fù)載的多部分/相關(guān) 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="qwawimqqmiuu" 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 和圖像作為有效負(fù)載的多部分/相關(guān) POST的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在嘗試從 Chrome 擴(kuò)展程序中將圖像(帶有元數(shù)據(jù))發(fā)布到 Picasa 網(wǎng)絡(luò)相冊(cè).請(qǐng)注意,正如我在此處所述,使用 Content-Type image/xyz 的常規(guī)帖子有效.但是,我希望包含描述/關(guān)鍵字和 協(xié)議規(guī)范 描述了 multipart/related 格式 帶有 XML 和數(shù)據(jù)部分.

                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 和用戶文件輸入獲取數(shù)據(jù).我檢索一個(gè)二進(jìn)制文件使用

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

                FileReader.readAsBinaryString(file);
                

                假設(shè)這是我在 FileReader 加載字符串后的回調(diào)代碼:

                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 函數(shù)只是從輸入值和 XML 模板生成多部分,并產(chǎn)生完全相同的輸出 作為規(guī)范(除了..二進(jìn)制圖像數(shù)據(jù)..),但為了完整起見,這里是:

                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 有效負(fù)載與原始圖像數(shù)據(jù)不同,因此會(huì)導(dǎo)致錯(cuò)誤請(qǐng)求(Picasa 不會(huì)接受圖像),盡管在使用時(shí)它工作正常

                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 二進(jìn)制圖像包含在多部分中?我認(rèn)為它只是通過將它附加到 xml 字符串而被破壞,但我似乎無法修復(fù)它.

                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.

                請(qǐng)注意,由于 Picasa 中存在 舊錯(cuò)誤,base64 不是解決方案.

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

                推薦答案

                XMLHttpRequest 規(guī)范 聲明使用 .send() 方法發(fā)送的數(shù)據(jù)將轉(zhuǎn)換為 unicode,并編碼為 UTF-8.

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

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

                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,這是我遇到類似問題時(shí)寫的.為了防止 Unicode 轉(zhuǎn)換,所有數(shù)據(jù)都添加到一個(gè)數(shù)組中,最后作為 傳輸數(shù)組緩沖區(qū).根據(jù)規(guī)范,字節(jié)序列在傳輸時(shí)不會(huì)被觸及.

                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!
                }
                

                當(dāng)您使用 .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!
                }
                

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

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

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 ajax 調(diào)用完成)
                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 無法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (301 302))
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)
                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="qwawimqqmiuu" 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'>

                          主站蜘蛛池模板: 日韩精品一区二区三区四区 | 中文在线一区二区 | 久久久91 | 国产日韩久久 | 久久久影院 | 日韩电影一区二区三区 | 国产精品日韩在线 | 九九热这里只有精品在线观看 | 日韩免费看视频 | 亚洲第一中文字幕 | 精品一区二区三区91 | 日日av| 男女视频在线观看网站 | 国产一区视频在线 | 一区二区三区四区电影视频在线观看 | 中文字幕综合 | 天天操妹子| 一级黄色片在线看 | 一区二区三区不卡视频 | 国产精品爱久久久久久久 | 国产精品久久久久久妇女 | 一级片在线观看 | 天天爽夜夜骑 | 中文字幕1区2区3区 亚洲国产成人精品女人久久久 | 天天操操操操操 | h视频在线播放 | 国产精品毛片在线 | 久久精品99国产精品日本 | 精品国产青草久久久久96 | 亚洲综合在线视频 | 日韩在线一区二区三区 | 国产精品a免费一区久久电影 | 精品国产不卡一区二区三区 | 国产精品18hdxxxⅹ在线 | 免费在线观看黄网站 | 欧美成人精品 | 一区二区高清不卡 | 涩爱av一区二区三区 | 欧美一二三 | 午夜国产一级片 | 成人免费激情视频 |