--
You received this message because you are subscribed to the Google Groups "Assembla API Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to assembla-api-d...@googlegroups.com.
To post to this group, send email to assembla...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
string path = @"/~App_Data/ProjectFiles/" + projectFilesToSpace.Guid.ToString() + "/" + item.Name;
// set file to stream
FileStream stream = new FileStream(item.FullName, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stream);
byte[] data = reader.ReadBytes((int)reader.BaseStream.Length);
spacefile.file = data;
spacefile.name = item.Name;
spacefile.folder_name = "Project Request Files";
string assemblaBaseUrl = "https://bigfiles.assembla.com";
RestClient assemblaClient = new RestClient(assemblaBaseUrl)
{
};
var request = new RestRequest("/v1/spaces/" + spaces.id + "/documents.json", RestSharp.Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Accept", "application/json");
request.AddHeader("X-Api-Key", creds.ApiKey);
request.AddHeader("X-Api-Secret", creds.ApiSecret);
request.AddHeader("Content-Type", "multipart/form-data");
//request.AddQueryParameter("document[file]","@" + item.FullName);
//request.AddQueryParameter("document[name]", item.Name);
//request.AddQueryParameter("document[folder_name]", spacefile.folder_name);
request.AddJsonBody(new { document = spacefile }); // required to add a namespace to the serialized json object required by assembla
var response = assemblaClient.Post<AssemblaSpace>(request); // save the new space document
Content-Type multipart/form-data
header to your request headers, no JSON or XML data bodies is supported during file creation