Attach file to post using C# RestSharp and Drupal Services I'm writing a C# app that posts to Drupal using Rest calls to the Services module, I can connect and create new nodes easily but I cannot figure out how to attach files to the nodes.
Using the RestSharp library for C#, this is the code:

var request = new RestRequest("...node/12/attach_file.json", Method.POST);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddCookie(my_session_name, my_sessid);
request.AddHeader("X-CSRF-Token", restResponse.Data.token);
request.AddParameter("field_name", "field_done");
request.AddFile("file", @"C:\pathtomyfile.png");
var response = client.Execute(request);


No errors are returned, status is 200 but the response is empty and nothing is uploaded in Drupal! And by the way the node date looks like modified, so something worked...!

The AddFile method of RestSharp is multipart and so the attach_file of Drupal:


  Upload and attach file(s) to a node. POST multipart/form-data to node/123/attach_file


Any help?
I have figured it out this way, sorry for late posting the answer:

// FIRST LOGIN
var client = new RestClient("http://....../");
var request = new RestRequest("user/login.json", Method.POST);
request.AddHeader("Content-Type", "x-www-form-urlencoded");
request.AddParameter("username", username);
request.AddParameter("password", password);
var restResponse = client.Execute&lt;Login&gt;(request);


Now upload a picture:

public string UploadPic(string path, Login login)
{
    var request = new RestRequest("file.json", Method.POST);
    request.RequestFormat = RestSharp.DataFormat.Json;
    request.AddCookie(login.session_name, login.sessid);
    request.AddHeader("X-CSRF-Token", login.token);
    request.AddParameter("uid", login.user.uid);
    string filevalue = System.Convert.ToBase64String(file_get_byte_contents(path));
    request.AddParameter("file", filevalue);
    request.AddParameter("filename", path.Split(new Char[] { '\\', '/' }).Last());
    var response = client.Execute&lt;DFile&gt;(request);

    return response.Data.fid;
}

static byte[] file_get_byte_contents(string fileName)
{
    byte[] sContents;
    if (fileName.ToLower().IndexOf("http:") &gt; -1)
    {
        // URL 
        System.Net.WebClient wc = new System.Net.WebClient();
        sContents = wc.DownloadData(fileName);
    }
    else
    {
        // Get file size
        FileInfo fi = new FileInfo(fileName);

        // Disk
        FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);
        sContents = br.ReadBytes((int)fi.Length);
        br.Close();
        fs.Close();
    }

    return sContents;
}


Where the class Login and DFile are the following: 

public class DFile
{
    public string fid { get; set; }
    public string uid { get; set; }
    public string filename { get; set; }
    public string uri { get; set; }
    public string filemime { get; set; }
    public string filesize { get; set; }
    public string status { get; set; }
    public string timestamp { get; set; }
}
public class Login
{
    public string sessid { get; set; }
    public string session_name { get; set; }
    public string token { get; set; }
    public User user { get; set; }
}