简体   繁体   中英

POSTMAN file upload with multiple keys

Hi i am developing multiple file upload module in angularjs as fron end. I am using FormData to send file. Hence it is multiple file upload i am looping through files and appending file to FormData. Along with this i am sending one more extra params as well.

 var files = new FormData();
        angular.forEach(this.pendingFiles, function (value, index) {
            files.append(index, value);
            files.append('data', angular.toJson(index).replace(/['"]+/g, ''));
        });
  return $http.post(this.uploadUrl, files, {
            transformRequest: angular.identity,
            headers: {
                'Content-Type': undefined
            }
        })

Below is my directive

myapp.directive('fileModel', ['fileUpload', function (fileUpload) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            element.bind("change", function (evt) {
                fileUpload.pendingFiles[attrs.fileModel] = evt.target.files[0];
            });
        }
    };
}]);

Above code works fine when i run angularjs script. I am trying to upload files using POSTMAN. I am struggling here how can i send below data

  files.append(index, value);
  files.append('data', angular.toJson(index).replace(/['"]+/g, ''));

normal file upload i know. My problem is i have one extra params data. I am not sure how can i send that via POSTMAN? Can someone help me in this regard? Any help would be appreciated. Thank you.

In postman, set method type to POST.

Then select Body -> form-data -> Enter your parameter name (file according to your code) For rest of "text" based parameters, you can post it like normally you do with postman. You can see in the image below for an example. 在此处输入图片说明

But probably you want to make the data key dynamic in your code. Otherwise if you are using the same key name with multiple values, then at server side it should be handled as an array 'data':['Passport','Visa']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM