I am trying to recreate a curl command to upload a file in C# by using System.Net.WebClient or another method, and I'm just not having luck sending the file and the name-value stuff together, as well as the auth that curl uses. Anyone know the trick to this? I am limited to framework 4.0.
I just need to send a simple csv file up to a URL, as described here: http://quickfuseapps.com/docs/api/sdb_upload_csv
The command itself is:
curl -u username:password -F tablekey=username:customers -F mode=replace -F csv=@customerdata.csv http://quickfuseapps.com/api/1/sdb/upload/csv
I tried this using a code snippet and class I found, but it doesn't allow for the network credentials
Helpers.MultipartForm form = new Helpers.MultipartForm("http://quickfuseapps.com/api/1/sdb/upload/csv");
form.SetField("tablekey", "user:table");
form.SetField("mode", "replace");
// NO auth method to set credentials
form.SendFile(@"d:\test.csv"); form.SetField("tablekey", "user:table");
form.SetField("mode", "replace");
// NO auth method to set credentials
form.SendFile(@"d:\test.csv");
Here's code that will set form fields and auth, but doesn't also allow for the file upload
using (var client = new WebClient())
{
var values = new NameValueCollection();
values.Add("app_id", "5gxWWnLlg");
values.Add("tablekey", "user:table");
values.Add("dial_col", "PhoneNumber");
values.Add("result_col", "outbound_result");
client.Credentials = new NetworkCredential("user", "pwd");
client.Encoding = Encoding.ASCII;
//var response = client.UploadValues("http://quickfuseapps.com/api/1/outbound/queue", values);
var response = client.UploadValues("http://quickfuseapps.com/api/1/outbound/queue/", "POST", values);
var responseString = Encoding.Default.GetString(response);
}