使用 angularjs 将带有表单数据的字节集合发送到 api [英] Sending byte collections with form form data to api using angularjs
问题描述
我必须将字节数组与字段数据一起发送到 api,如图所示.我对使用 angularjs 社区提供的模块有疑问,因为它没有说明数据是如何传输的,而且我几乎没有了解它.所以我想将从按钮上传到字节集合的任何文件发布到带有表单数据的api.这是我的 api 的图像.
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.
我在服务器上使用 .NET Web API 2.0 来接收和处理客户端传输.这是您的选择吗?
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?
我确信除 Web API 之外还有其他服务器选项,但我的一半答案取决于此服务器端功能.
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.
问候....
我至少可以给你一些使用 angular 的客户端代码.在发送到服务器之前,我做了很多客户端压缩并将数据压缩成字节数组.
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.
让我知道这是否有用.
这是一些客户端代码.
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?
这篇关于使用 angularjs 将带有表单数据的字节集合发送到 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!