从IE11工人用发送的multipart / form-data的二进制数据 [英] Sending binary data using multipart/form-data from a worker with IE11

查看:2181
本文介绍了从IE11工人用发送的multipart / form-data的二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从IE工人发的multipart / form-data的。我已经使用Chrome,火狐,Safari浏览器做了它使用 FORMDATA 对象(不支持IE浏览器,我需要一个手动的)

我要送二进制数据是加密的js加密数据。随着 FORMDATA 对象我做的:

  VAR ENC =新的缓冲区(encrypted.ciphertext.toString(CryptoJS.enc.Base64)的base64');
formData.append(userfile的,新的斑点([finalEncrypted] {类型:应用程序/八位字节的二进制'})'加密')
这工作正常产生这样一个多(错过了它的某些部分):

请求头:

 接受:* / *
接受编码:gzip,紧缩
缓存控制:无缓存
连接:保持活动
内容长度:30194
内容类型:多重/ form-data的;边界= WebKitFormBoundary0.gjepwugw5cy58kt9

正文:

   -  WebKitFormBoundary0.gjepwugw5cy58kt9
内容处置:表格数据; NAME =userfile的;文件名=加密
内容类型:二进制

所有的二进制数据

   -  WebKitFormBoundary0.cpe3c80eodgc766r--

使用手册的multipart / form-data的

  IE11不接受readAsBinaryString(德precated)

我想避免发送EN codeD数据的base64(readAsDataURL)(33%负载)

我要送二进制数据是加密的js加密数据。
我想:

  finalEncrypted =新的缓冲区(encrypted.ciphertext.toString(CryptoJS.enc.Base64)的base64');

然后我手动多部分我试图缓冲转换为二进制字符串:

  item.toString('二进制')

多部分结果看起来如下所示:

   -  WebKitFormBoundary642013568702052
内容处置:表格数据; NAME =userfile的;文件名=加密
内容类型:二进制

所有的二进制数据

<$p$p><$c$c>ÐçÀôpRö3§]g7,UOÂmR¤¼ÚS\"Ê÷UcíMÆÎÚà/,hy¼øsËÂú@WcGvºÆÞ²i¨¬Ç~÷®}éá?'é·J]þ3«áEÁÞ,4üBçðºÇª bUÈú4
ŧ\\ AO =òEnýR_ [1J \\ O型ïǹÇ\\Ûøü^%&éÓÁóJNÓï¹LsXâxGT; \\ AAV×Þ^÷·{|'

在.NET服务器,我们检查客户端计算哈希与服务器计算。该散列不匹配服务器的答复。这让我觉得我不是正确发送文件。


解决方案

看起来你还没有得到解决,至少你,如果你有一个没有张贴在这里。

在我结束我使用jQuery它处理的实际岗位的低层次细节问题。

这可能是你正在做一个小小的一点毛病和IE浏览器的失败。既然你不显示你FORMDATA使用什么。这是相当困难的,看你是否曾有一个错误。

  //第1步设置POST数据
VAR数据=新FORMDATA();
data.append(some_variable_name,value_for_that_variable);
data.append(some_blob_var_name,my_blob);
data.append(some_file_var_namemy_file);//步骤2选择
VAR ajax_options =
    {
        方法:POST,
        过程数据:假的,
        数据:数据,
        的contentType:假的,
        错误:功能(jqxhr,result_status,ERROR_MSG)
        {
            //上的错误反应
        },
        成功:功能(数据,result_status,jqxhr)
        {
            //成功反应
        },
        完成:功能(jqxhr,result_status)
        {
            //在完成反应(后错误/成功回调)
        },
        数据类型:XML//服务器预计将只返回XML
    };//第3步发送
jQuery.ajax(URI,ajax_options);

步骤1。

创建一个 FORMDATA 对象,并填写表格数据,包括变量和文件。你甚至可以添加的斑点的(JavaScript对象,将转换为 JSON 如果我是正确的。)

步骤2。

创建一个 ajax_options 对象根据自己的喜好。虽然我在这里展示你的过程数据数据的contentType ,因为他们必须在情况下,你要发送 FORMDATA 。至少,这对我的作品......它可能会改变一些这些值。

数据类型应设置为你的回报期望任何类型的。

步骤3。

发送使用阿贾克斯()从jQuery库功能的要求。按要求在客户端的浏览器将建立适当的标题和结果。

I'm trying to send a multipart/form-data from a worker with IE. I've already done it with Chrome, Firefox, Safari using formData objects (not supported IE, I need a manual one)

The binary data I'm sending is a crypto-js encrypted data. With formData objects I do:

var enc = new Buffer(encrypted.ciphertext.toString(CryptoJS.enc.Base64), 'base64');
formData.append("userFile" , new Blob([finalEncrypted], {type: 'application/octet-binary'}), 'encrypted')
this works fine generating a multipart like this(missed some parts of it):

request headers:

Accept:*/*
Accept-Encoding:gzip, deflate
Cache-Control:no-cache
Connection:keep-alive
Content-Length:30194
Content-Type:multipart/form-data; boundary=WebKitFormBoundary0.gjepwugw5cy58kt9

body:

--WebKitFormBoundary0.gjepwugw5cy58kt9
Content-Disposition: form-data; name="userFile"; filename="encrypted"
Content-Type: binary

all binary data

--WebKitFormBoundary0.cpe3c80eodgc766r--

With the manual multipart/form-data:

IE11 doesn't accept readAsBinaryString(deprecated)

I would like to avoid sending base64 encoded data(readAsDataURL)(33% payload)

The binary data I'm sending is a crypto-js encrypted data. I'm trying:

finalEncrypted = new Buffer(encrypted.ciphertext.toString(CryptoJS.enc.Base64), 'base64');

then in my manual multipart I tried to convert the buffer to a binary string:

item.toString('binary')

the multipart result looks looks this:

--WebKitFormBoundary642013568702052
Content-Disposition: form-data; name="userfile"; filename="encrypted"
Content-Type: binary

all binary data

ÐçÀôpRö3§]g7,UOÂmR¤¼ÚS"Ê÷UcíMÆÎÚà/,hy¼øsËÂú@WcGvºÆÞ²i¨¬Ç~÷®}éá?'é·J]þ3«áEÁÞ,4üBçðºÇª bUÈú4
T\Ãõ=òEnýR  _[1J\O-ïǹ C¨\Ûøü^%éÓÁóJNÓï¹LsXâx>\aÁV×Þ^÷·{|­'

On the .NET server we check the hash calculated on client versus calculated on server. Server reply that hashes doesn't match. This makes me think that I'm not sending the file correctly.

解决方案

It looks like you did not yet get a solution, at least you did not post it here if you had one.

On my end I use jQuery which handles the low level nitty gritty of the actual post.

It may be that you are doing one small thing wrong and IE fails on it. Since you do not show what you used with FormData. It is rather difficult to see whether you had a mistake in there.

// step 1. setup POST data
var data = new FormData();
data.append("some_variable_name", "value_for_that_variable");
data.append("some_blob_var_name", my_blob);
data.append("some_file_var_name", my_file);

// step 2. options
var ajax_options =
    {
        method: "POST",
        processData: false,
        data: data,
        contentType: false,
        error: function(jqxhr, result_status, error_msg)
        {
            // react on errors
        },
        success: function(data, result_status, jqxhr)
        {
            // react on success
        },
        complete: function(jqxhr, result_status)
        {
            // react on completion (after error/success callbacks)
        },
        dataType: "xml" // server is expected to return XML only
    };

// step 3. send
jQuery.ajax(uri, ajax_options);

Step 1.

Create a FormData object and fills the form data, that includes variables and files. You may even add blobs (JavaScript objects, will be transformed to JSON if I'm correct.)

Step 2.

Create an ajax_options object to your liking. Although here I show your the method, processData, data, contentType as they must be in case you want to send a FormData. At least, that works for me... It may be possible to change some of those values.

The dataType should be set to whatever type you expect in return.

Step 3.

Send the request using the ajax() function from the jQuery library. It will build the proper header and results as required for the client's browser.

这篇关于从IE11工人用发送的multipart / form-data的二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆