1

Using AngularJS, I'm making a post request to send an array of objects, with each object comprising of string, boolean and object values. The object represents a file uploaded by the user. Before the request, it shows as a file object (signedPoaDoc), and after a response, the data shows that a file was included in the reqeust

enter image description here

We are having issues in the back-end, but the back end developer is saying that the payload in the console is showing no file is being provided, but an empty object for signedPoaDoc.

enter image description here

html

<form name="validationForm" novalidate>
    <data-ng-init="formData.designatedStates">
        <div data-ng-repeat="states in formData.designatedStates"
              data-ng-init="formData.designatedStates.states;
                            states.signedPoaDoc"> 
            <div>
                <label for="{{states.stateName}}">{{states.stateName}}: </label>
                <div>                   
                    <input type="file" name="{{states.stateName}}"
                           data-ng-model="states.signedPoaDoc" 
                           accept="application/pdf" required>
                </div>

            </div>                          
        </div>
    </div>
</form>

JS

function removeCost(item) {
    delete item.validationCost_EUR;
    delete item.validationCost_USD;
    if(!item.signedPoaDoc) { item.signedPoaDoc = null; };
    return item;
}

function submitPoaDocuments(data) {

    var formData = new FormData();

    var designatedMap = data.designatedStates.map(removeCost);
    var extensionMap = data.extensionStates.map(removeCost);
    var validationMap = data.validationStates.map(removeCost);

    formData.append('patentID', patent.patentID);
    formData.append('designatedStates', designatedMap);
    formData.append('extensionStates', extensionMap);
    formData.append('validationStates', validationMap);
    validationService.submitPoas(formData)
    .then(
         function(response){

         }
    )
}

As you can see we assigned the signedPoaDoc property from the view via ngModel.

Question

Is this correct that no file is being provided to back end, or is this something to do with chrome and the way they display the payload?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Patrick McDermott
  • 1,220
  • 1
  • 15
  • 30
  • From the payload no file is being sent. You are more than likely not sending the data correctly. In order to send data and files together in a ajax post request you need to pass a FormData object to the api, eg `XMLHTTPRequest`/`fetch` or whatever library you maybe using. Provide the code you are using to make the request so we can help you better – Patrick Evans Mar 09 '20 at 13:59
  • @PatrickEvans just updated with code – Patrick McDermott Mar 09 '20 at 14:43
  • 1
    The core `ng-model` directive does not work with `` out of the box. See [How to enable `` to work with ng-model](https://stackoverflow.com/a/43074638/5535245) – georgeawg Mar 09 '20 at 19:39

0 Answers0