【问题标题】:Sending byte collections with form form data to api using angularjs使用angularjs将带有表单数据的字节集合发送到api
【发布时间】:2015-10-15 05:28:49
【问题描述】:

我必须将一个字节数组与字段数据一起发送到api,如图所示。我对使用angularjs社区提供的模块有疑问,因为它没有说明数据是如何传输的,我几乎没有了解它。 所以我想将任何从按钮上传到字节集合的文件发布到带有表单数据的 api。这是我的 api 的图像。

实际上我面临的问题是将文件更改为角度字节,然后再次找到一个模块来上传字节数组。 我见过一些字节上传技术,但与我需要的相比,它们完全不同。如果你有更好的方法来查看这个,请告诉我一些

【问题讨论】:

    标签: angularjs file api byte uploading


    【解决方案1】:

    达格姆,

    我没有足够的积分来为你的问题添加评论,所以我将在这里开始回答。

    我在服务器上使用 .NET Web API 2.0 来接收和处理客户端传输。这是您的选择吗?

    我确信除了 Web API 之外还有其他服务器选项,但我的答案有一半取决于此服务器端功能。

    告诉我,我会尽力帮助你的。

    问候....

    我至少可以给你一些使用 Angular 的客户端代码。在发送到服务器之前,我做了很多客户端压缩和数据压缩成字节数组。

    让我知道这是否有用。

    这是一些客户端代码。

    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?

    【讨论】:

    • 在将你们中的一些调整和 tbl_transaction 作为 json 参数后,它让我了解了一些方法,谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    • 2018-01-24
    • 2020-10-28
    • 2018-10-09
    • 2014-02-16
    相关资源
    最近更新 更多