0

Let's say we have an application form that contains entries for text, numbers, checkboxes, and file uploads.

Would it be best practice to have two HttpClient services (one for sending the text/number/checkbox data the user entered and one for sending the file data the user uploaded) to post this data to the same URL?

Michael O
  • 71
  • 1
  • 7
  • 1
    For what? You can use one service with multiple methods, one for GET, one for POST, one for PUT and so on. – user3804427 Mar 29 '19 at 10:41
  • I thought that for submitting different components of a form, I would require different services. If I can use one service with multiple methods, one for uploading files, then returning a POST, and another for posting text/number/checkbox data, then that would be extremely convenient. Thank you! – Michael O Mar 29 '19 at 10:50

3 Answers3

0

Use One Post data with multipart/form-data as content type . check this out

mcsekar
  • 416
  • 3
  • 13
0

I am currently working on a project similar to what you described. I created two services. one service that controls my text, numbers, files and the likes.And the other for user authentications. But I don't think it is needful to create more than one service for files and text input.

taiwo sunday
  • 33
  • 1
  • 8
  • I agree, I don't think creating more than two services (at least for this application) are necessary, just in case there was another aspect of the application that would warrant a service to deal with it. – Michael O Mar 29 '19 at 11:09
0

What I ended up doing was having the form contain an array of objects that take two properties, name and data. I've assigned the name to the file's name, and I've converted the file content into base64 assigning it to data.

I ended up using just one Post request as the first comment by @user3804427 suggested.

Michael O
  • 71
  • 1
  • 7