通过Javascript

时间:2019-06-30 10:52:09

标签: javascript rest multipartform-data

发布请求:

$('#input-b6').on('filelock', function (event, filestack, extraData) {
            var strFiles = "";
            Object.keys(filesBase64).forEach(function(key) {
                console.log(key, filesBase64[key]);
                sforce.connection.remoteFunction({
                    url : 'https://localrestapi.herokuapp.com/consumeFiles',
                    onSuccess : successCallBack,
                    onFailure : errorCallBack,
                    method : 'POST',
                    requestHeaders : 'Content-Type: multipart/form-data',
                    async : true,
                    formData : 'filename:' +filesBase64[key],
                    timeout : 120000
                });
            });
        });

通过文件读取器读取文件:

   var reader = new FileReader();
            var file = file;
            reader.file = file;
            reader.onload = function (event) {
                var filetype = file.type;
                var filename = file.name;
                var fileContent = String(event.target.result);
                var index = fileContent.indexOf('base64,');
                var attachBody = fileContent.substring(index + 7);
                try {
                    var objFileBase64 = {
                        name: filename,
                        contentType: filetype,
                        body: attachBody,
                        description: filename,
                        uploadDate: new Date()
                    };
                    filesBase64[strInputFileId + '&&&' + filename + '&&&' + file.size] = objFileBase64
                } catch (error) {
                    console.log(error);
                }
            };
            reader.readAsDataURL(file);
        });

我已经在spring boot + heroku https://localrestapi.herokuapp.com/consumeFiles中托管了一个端点来测试我的逻辑,当通过邮递员或任何其他Rest Client命中该api时效果很好,但是当通过javascript中的逻辑命中时,它显示{{1} }

如何通过javascript创建分段请求?

0 个答案:

没有答案