Hi I am trying to write a C# client for this API: https://www.directdebit.co.za/api/dos.svc
On their endpoint for "/batch/eft/" they want me to send them a file with the formData Paramater Type. As far as I understand I should be using the MultipartContent class to do this. I've managed to read the file into a string variable, I just need to assign that to a multipart/formData paramater somehow. Here's my code so far:
// Upload a file to Direct Debit via the API
public async void UploadFile(string filePath)
{
if (!File.Exists(filePath))
{
throw new ArgumentException($"{filePath} does not exist");
}
var sb = new StringWriter();
using (var fs = File.OpenRead(filePath))
{
var b = new byte[1024];
while (fs.Read(b, 0, b.Length) > 0)
{
sb.Write(b);
}
}
var content = sb.ToString();
var hc = GenerateHttpClient();
var postBody = new MultipartContent();
// I am a little confused. What do I do now?
var resp = await hc.PostAsync(url + "/batch/eft", postBody);
resp.EnsureSuccessStatusCode();
}
Thanks in advance.
Arie