Search code examples
angularjsangular-file-upload

Lib angular file upload with field data object json


I'm using lib angular-file-upload.

How do I add the date field of $http request on request below:

var app = angular.module('app', ['angularFileUpload']);

app.controller('Aula21Controller', function($scope, FileUploader){

    var uploader = $scope.uploader = new FileUploader({
        url : 'http://localhost:8080/work/v1/chats',
        alias: 'message-body',
        headers: {'X-Client-Instance': '1.221@0000010000083359', 'Content-Type': 'multipart/formdata'},    
    });

In my request needs to send a json object (date field) with the items below:

json object - data 

{
    "receiver":"", 
    "localAddress":"", // ip 
    "attachment":"", // name file
    "content":"" // content message
}

Thanks.


Solution

  • Assuming you're using this lib: https://github.com/nervgh/angular-file-upload/, you can pass additional data using the formData property