发送字节集合与form表单数据的API使用angularjs [英] Sending byte collections with form form data to api using angularjs

查看:213
本文介绍了发送字节集合与form表单数据的API使用angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组,如图所示figure.I有一个疑问关于使用,因为它没有说明有关数据是如何转移由angularjs社会提供的模块领域的数据一起发送至API和我没有什么了解一下吧。
所以我想从后一键上传到一个字节集合与表单数据的API的任何文件。这里是我的API的图像。

在这里输入的形象描述

其实我面临的问题是不断变化的角度,以字节的文件,然后再找到一个模块上传的字节数组。
我见过一些字节上传技术,但比起我need.If你有一些更好的方式来看待这个请告诉我他们正在退出一些不同的


解决方案

Dagm,

我没有足够的积分评论添加到您的问题,所以我就从这里开始了答案。

我使用的服务器上的.NET Web API 2.0接收并处理客户端的传输。这是给你一个选择吗?

我相信,还有比网络API以外的其他服务器的选择,但我的回答有一半取决于该服务器端的功能。

让我知道了,我会尽力帮助你。

祺....

我至少可以给你一些客户code,与棱角分明的作品。我发送到服务器之前做大量的客户端压缩和数据转换成字节数组的COM pression的。

让我知道这将是有益的。

下面是一些客户端code。

\r
\r

ItemHttpService.prototype.uploadItem =功能($ HTTP,ID,TRANSACTION_ID,文件名, FileExt,文件,itemUploadCallback){\r
        $ HTTP({\r
            //网页API 2.0具体。 ItemUpload引用ItemUploadController。 UploadItems是方法名。\r
            网址:'API / ItemUpload / UploadItems',\r
            方法:POST,\r
            标题:{内容类型:应用程序/八位字节流},\r
            数据:新Uint8Array(文件),\r
            params:一个{\r
                //这里的其他参数,可以包括有关上传的元数据串\r
                编号:ID,\r
                TRANSACTION_ID:TRANSACTION_ID,\r
                文件名:文件名,\r
                FileExt:FileExt\r
            },\r
            transformRequest:[] //用于处理字节数组数据。\r
        })。成功(功能(响应状态){//这是我如何处理响应的一个例子。\r
            如果(状态=== 200){\r
                itemUploadCallback(响应); //我记得,响应是一个JSON字符串化的结果。\r
            }其他{\r
                itemUploadCallback('');\r
            }\r
        })错误(功能(状态){\r
            itemUploadCallback(JSON.stringify(您的错误处理));\r
        });\r
    };\r
\r
不知道tblPeriodical_Transaction是什么。你能否解释一下?

\r

\r
\r

I have to send a byte array to an api along with the field data as shown in the figure.I have a doubt about using the modules provided by angularjs community because its not stating about how the data is transferred and I have little understanding about it. so I want to post any file uploaded from a button to a byte collection to an api with the form data. here is an image for my api.

Actually the problem I faced is changing the file to byte in angular and again finding a module to upload the byte array. I have seen some of byte uploading techniques but they are quit different compared to what I need.If you have some better ways to look at this please show me some

解决方案

Dagm,

I do not have enough points to add a comment to your question, so I will start an answer here.

I am using the .NET Web API 2.0 on the server to receive and process the client transmission. Is this an option for you?

I am sure that there are other server options other than Web API, but half of my answer depends on this server-side functionality.

Let me know, and I will try to assist you.

Regards....

I can at least give you some client code that works with angular. I do a lot of client side compaction and compression of data into byte arrays before sending to the server.

Let me know if this would be useful.

Here is some client code.

ItemHttpService.prototype.uploadItem = function ($http, Id, Transaction_Id, FileName, FileExt, File, itemUploadCallback) {
        $http({
            // Web API 2.0 specific. ItemUpload references the ItemUploadController. UploadItems is method name.
            url: 'api/ItemUpload/UploadItems',
            method: 'POST',
            headers: { 'Content-Type': 'application/octet-stream' },
            data: new Uint8Array(File),
            params: {
                // Other params here, including string metadata about uploads
                Id: Id,
                Transaction_Id: Transaction_Id,
                FileName: FileName,
                FileExt: FileExt
            },
            transformRequest: [] // Used to handle the byte array data.
        }).success(function (response, status) {// This is one example of how I handled a response.
            if (status === 200) {
                itemUploadCallback(response); // As I recall, the response is a JSON stringified result. 
            } else {
                itemUploadCallback('');
            }
        }).error(function (status) {
            itemUploadCallback(JSON.stringify("Your error handling here"));
        });
    };

Not sure what the tblPeriodical_Transaction is. Can you elaborate?

这篇关于发送字节集合与form表单数据的API使用angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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