Skip to content

Instantly share code, notes, and snippets.

@bverbeken
Last active July 22, 2018 13:37
Show Gist options
  • Select an option

  • Save bverbeken/8282925 to your computer and use it in GitHub Desktop.

Select an option

Save bverbeken/8282925 to your computer and use it in GitHub Desktop.

Revisions

  1. bverbeken revised this gist Jan 6, 2014. 2 changed files with 34 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion app.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ $scope.saveMyObject = function () {
    method: 'POST',
    url: '/my/url',
    headers: {
    'Content-Type': undefined
    'Content-Type': undefined // --> makes sure the boundary is set in the Content-Type header, see result file
    },
    data: {
    file: $scope.file,
    33 changes: 33 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    Request Headers
    ===============
    POST /my/url HTTP/1.1
    Host: localhost:8083
    Connection: keep-alive
    Content-Length: 355
    Authorization: Basic ZDpk
    Accept: application/json, text/plain, */*
    Origin: http://localhost:8083
    X-Requested-With: XMLHttpRequest
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryPcJBO0iJ6WlKSynv
    Referer: http://localhost:8083/
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: en-US,en;q=0.8,fr;q=0.6


    Request Payload
    ===============

    ------WebKitFormBoundaryPcJBO0iJ6WlKSynv
    Content-Disposition: form-data; name="file"

    somefile.txt
    ------WebKitFormBoundaryPcJBO0iJ6WlKSynv
    Content-Disposition: form-data; name="startDate"

    2014-01-09
    ------WebKitFormBoundaryPcJBO0iJ6WlKSynv
    Content-Disposition: form-data; name="endDate"

    2014-01-30
    ------WebKitFormBoundaryPcJBO0iJ6WlKSynv--
  2. bverbeken created this gist Jan 6, 2014.
    21 changes: 21 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    $scope.saveMyObject = function () {
    return $http({
    method: 'POST',
    url: '/my/url',
    headers: {
    'Content-Type': undefined
    },
    data: {
    file: $scope.file,
    startDate: $scope.startDate,
    endDate: $scope.endDate
    },
    transformRequest: function(data) {
    var fd = new FormData();
    angular.forEach(data, function(value, key) {
    fd.append(key, value);
    });
    return fd;
    }
    });
    };
    8 changes: 8 additions & 0 deletions controller.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    ...

    @RequestMapping(method = POST, consumes = "multipart/form-data")
    public void submit(@RequestBody MultiValueMap<String, Object> requestBody) {

    // do stuff

    }