我想上传使用Zendesk API v2的图像,我使用RestSharp发布文件到/api/v2/uploads.json,并且该文件出现在一旦我创建了票证并添加附件,问题是如果我上传的图像不会在票证上打开,那么它会被破坏,如果它的.txt文件中有额外的数据,这是我的方法:错误,同时尝试上传文件到Zendesk Api 2在c#
var client = new RestSharp.RestClient(model.RequestUri);
client.Authenticator = new HttpBasicAuthenticator(string.Format("{0}/token", model.Username), model.Password);
var request = new RestRequest("/api/v2/uploads.json", Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "text/plain");
request.AlwaysMultipartFormData = true;
request.Parameters.Clear();
request.RequestFormat = RestSharp.DataFormat.Json;
//request.AddBody(createUpload);
byte[] bytes = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Media/uploads/test.txt"));
request.AddFileBytes("Attachment", bytes, "test.txt", contentType: "text/plain");
request.AddParameter("filename", "test.txt");
IRestResponse response = client.Execute(request);
var content = JObject.Parse(response.Content);
return content["upload"]["token"].ToString();
这是附加到票所产生的txt文件:
-------------------------------28947758029299
Content-Disposition: form-data; name="filename"
test.txt
-------------------------------28947758029299
Content-Disposition: form-data; name="Attachment"; filename="test.txt"
Content-Type: application/octet-stream
testing txt
-------------------------------28947758029299--
原始文件只是有:
testing txt
任何想法的错误可能是什么?
谢谢。
你好@LeoTorres,我有同样的问题。你有没有得到它的修复。任何解决方案,而不使用JustEat的API –