0

I am having a hard time to convert the following curl POST to comply with the angular-file-upload format

curl  -H "Content-Type: multipart/form-data" --form "jobSettings=$body" --form "upload=@$file" ${URL}?key=$key

where:

@file - an image file provided as a parameter to the script call

$body - a JSON object that describes job parameters required by the server

Namely, I do not know how to pass --form parameters into formData of angular-file-upload (and even if formData is the right property to use for this task).

PS: I found this solution for posting an image as a JSON multipart/form-data data without relying on angular-file-upload, but I am still not sure how could I format jobSettings parameter within the data property of the $http.post(). I tried the following ways, since according to $http docs I am allowed to set data to String or Object types:

data: 'jobSettings={"analysis": {"paintings": [...]}}'

data: {'jobSettings': {"analysis": {"paintings": [...]}}'

Not working.

Anyone?

Community
  • 1
  • 1
Nikolay Melnikov
  • 1,345
  • 14
  • 24

1 Answers1

0

I finally managed to achieve the result by using angular-file-upload combined with the following setting for formData parameter of the FileUploader() instances:

$scope.uploader.formData.push({'jobSettings': JSON.stringify(jobSettings)});
Nikolay Melnikov
  • 1,345
  • 14
  • 24