【问题标题】:$http.post what format for data (body) when binary?$http.post 二进制时数据(正文)的格式是什么?
【发布时间】:2017-04-18 15:27:47
【问题描述】:

我想在 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 正文中发送的字段?

【问题讨论】:

    标签: javascript angularjs node.js http


    【解决方案1】:

    DOH,我只需要添加 , transformRequest: [] 以便 angularjs 不会对数据产生影响。

    $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
                        })
                    }, transformRequest: []
                }
            )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2016-06-25
      相关资源
      最近更新 更多