$ http.post二进制时数据(正文)的格式是什么?

时间:2016-12-03 23:56:54

标签: javascript angularjs node.js http

我想在angularjs $ http.post中发送二进制文件(例如图片)。

我在nodejs Buffer对象中有数据,这是一个Uint8Array实现。

我试过了:

$http.post("https://content.dropboxapi.com/2/files/upload",
                data,
                {
                    headers: {
                        'Content-Type': 'application/octet-stream',
                        'Authorization': 'Bearer ' + dSvc.GO.onlineStorage.D1.accessResponse.access_token,
                        'Dropbox-API-Arg': JSON.stringify({
                            "path": path,
                            "mode": "overwrite",
                            "mute": true
                        })
                    }
                }
            )

但是当数据到达服务器时,是更大的,并且图像已损坏。

如果我的起点是缓冲区(Uint8Array),我如何从那里到达可以在$ http.post正文中发送的字段?

1 个答案:

答案 0 :(得分:0)

DOH,我只需添加,transformRequest:[]以便angularjs不会废弃数据。

            using WatiN.Core; // IE Automation
...
            // verify current thread in STA.

            Settings.Instance.MakeNewIeInstanceVisible = false;

            var ieStaticInstanceHelper = new IEStaticInstanceHelper();
            Settings.AutoStartDialogWatcher = false;

            using (ieStaticInstanceHelper.IE = new IE())
            {
                string authCode = "";
                ieStaticInstanceHelper.IE.GoTo(GetAuthorizationLink());

                if (ieStaticInstanceHelper.IE.ContainsText("Scheduled System Maintenance"))
                {
                    throw new ApplicationException("eTrade down for maintenance.");
                }

                TextField user = ieStaticInstanceHelper.IE.TextField(Find.ByName("USER"));

                TextField pass = ieStaticInstanceHelper.IE.TextField(Find.ById("txtPassword"));

                TextField pass2 = ieStaticInstanceHelper.IE.TextField(Find.ByName("PASSWORD"));

                Button btn = ieStaticInstanceHelper.IE.Button(Find.ByClass("log-on-btn"));
                Button btnAccept = ieStaticInstanceHelper.IE.Button(Find.ByValue("Accept"));


                TextField authCodeBox = ieStaticInstanceHelper.IE.TextField(Find.First());

                if (user != null && pass != null && btn != null &&
                    user.Exists && pass2.Exists && btn.Exists)
                {
                    user.Value = username;
                    pass2.Value = password;
                    btn.Click();
                }

                btnAccept.WaitUntilExists(30);
                btnAccept.Click();

                authCodeBox.WaitUntilExists(30);
                authCode = authCodeBox.Value;

                SavePin(authCode);
            }