0

I want to upload an image to API where there are object names. Like this:

[ 
  {
    "Name": "0417BlogTop.png",
    "Description": null,
    "FileName": "" 
  } 
]

Do you have any examples on how to push the image name to the object "Name"? I have been trying to use FormData and adding formData.append(''). Nothing works. It sends nothing.

onuriltan
  • 3,730
  • 4
  • 25
  • 37
IssaChii
  • 55
  • 1
  • 9

2 Answers2

0

JSON objects just holds small data structures that can be strings, arrays, numbers, booleans etc. If you want to upload the an image through an API to the server, I suggest you to look at this post. It can give you an idea of different ways to upload an image through API

onuriltan
  • 3,730
  • 4
  • 25
  • 37
0

Thank you for you all answers! I got it fixed by using the program "Postman" to check first if the requests is working. Postman have also a suggestion code that will work for uploading files. I will add the example code:

var form = new FormData();
form.append("", "url");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://localhost:61870/colorprofile",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache",
    "Postman-Token": "504be690-da5e-4b73-ba25-cb6fcf042f37"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
IssaChii
  • 55
  • 1
  • 9