我想将文件上传到此api https://support.crowdin.com/api/add-file/
如何files使用RestSharp 创建一个名为的参数并向其中添加多个文件?
到目前为止,我已经编写了此代码,但是它不起作用,RestSharp似乎没有按预期上传文件。
var addUrl = new Uri($"https://api.crowdin.com/api/project/{projectIdentifier}/add-file?key={projectKey}&json=");
var restClient = new RestSharp.RestClient("https://api.crowdin.com");
var request = new RestSharp.RestRequest($"api/project/{projectIdentifier}/add-file", RestSharp.Method.POST);
request.AlwaysMultipartFormData = true;
request.AddQueryParameter("key", projectKey);
request.AddQueryParameter("json", "");
var files = new Dictionary<string, byte[]>
{
{ "testfile", File.ReadAllBytes(fileName) }
};
request.AddParameter("files", files, RestSharp.ParameterType.RequestBody);
var restResponse = restClient.Execute(request);
Run Code Online (Sandbox Code Playgroud)
这给我
{
"success":false,
"error":{
"code":4,
"message":"No files specified in request"
}
}
Run Code Online (Sandbox Code Playgroud)