AngularJS et création de requête multipart/form-data
Bonjour,
Avec AngularJS (et ngresource), je récupère deux objets JSON différents depuis un formulaire.
A partir de ces 2 éléments JSON, je génère une requête de type "multipart/form-data".
Le code est le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| {
method: 'POST',
transformRequest: function(data)
{
var objet1 = {"Objet1": data.objet1};
objet1 = angular.toJson(objet1);
var objet2 = {"Objet2": data.objet2};
objet2 = angular.toJson(objet2);
var fd = new FormData();
fd.append("Objet1",new Blob([objet1], { type: 'application/json; charset=ISO8859-15' }));
fd.append("Objet2",new Blob([objet2], { type: 'application/json; charset=ISO8859-15'}));
return fd;
},
headers: {'Content-Type':undefined, enctype:'multipart/form-data'}
} |
Ceci me génère la requête suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| Content-Type: multipart/form-data; boundary=---------------------------229961142931227
Headers: {Accept=[application/json, text/plain, */*], accept-encoding=[gzip, deflate], Accept-Language=[fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3], connection=[keep-alive], Content-Length=[510], content-type=[multipart/form-data; boundary=---------------------------229961142931227], enctype=[multipart/form-data], Host=[172.30.103.20:8181], Referer=[http://172.30.103.20:8181/ses-console/], User-Agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0]}
Payload: -----------------------------229961142931227
Content-Disposition: form-data; name="Objet1"; filename="blob"
Content-Type: application/json; charset=iso8859-15
{"Objet1":{"code":"STP","libelle":"sdd"}}
-----------------------------229961142931227
Content-Disposition: form-data; name="Objet2"; filename="blob"
Content-Type: application/json; charset=iso8859-15 content-id: <objet2>
{"Objet2":{"code":"AMMMSTP","libelle":"dfsdf"}}
-----------------------------229961142931227-- |
J'aimerais ajouté l'attribut "Content-id" dans chacune des parties afin d'obtenir la requête suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Content-Type: multipart/form-data; boundary=---------------------------229961142931227
Headers: {Accept=[application/json, text/plain, */*], accept-encoding=[gzip, deflate], Accept-Language=[fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3], connection=[keep-alive], Content-Length=[510], content-type=[multipart/form-data; boundary=---------------------------229961142931227], enctype=[multipart/form-data], Host=[172.30.103.20:8181], Referer=[<a href="http://172.30.103.20:8181/ses-console/]" target="_blank">http://172.30.103.20:8181/ses-console/]</a>, User-Agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0]}
Payload: -----------------------------229961142931227
Content-Disposition: form-data; name="Objet1"; filename="blob"
Content-Type: application/json; charset=iso8859-15
Content-id:<objet1>
{"Objet1":{"code":"STP","libelle":"sdd"}}
-----------------------------229961142931227
Content-Disposition: form-data; name="Objet2"; filename="blob"
Content-Type: application/json; charset=iso8859-15 content-id: <objet2>
Content-id:<objet2>
{"Objet2":{"code":"AMMMSTP","libelle":"dfsdf"}}
-----------------------------229961142931227-- |
Est-ce que quelqu'un aurait l'amabilité de m'aider?
Je vous remercie d'avance.
A+