xamarin通过休息发送大文件

时间:2016-05-27 11:10:26

标签: ios xamarin

我从服务器获得http error response 422并且不确定它是前端还是后端有问题。所以,如果您看到电话有任何问题,请告诉我。 :)

    public void AddFileToTask(int taskId, byte [] picture, NSDictionary   imageMetadata, Action<List<APFile>> callback)
    {

        var request = new RestRequest("/api/files");
        request.AddParameter("metadata", imageMetadata, ParameterType.GetOrPost);
        request.AddFile("file",picture, new Guid().ToString()+".jpg");
        request.AddHeader("Content-Type", "multipart/form-data");
        request.Method = Method.POST;
        request.RequestFormat = DataFormat.Json;
        client.ExecuteAsync (request, response => {
            if(response.ErrorException != null || response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                const string message = "Error retrieving response.  Check inner details for more info.";
                var responseException = new ApplicationException(message, response.ErrorException);
                throw responseException;
            } else {
                List<APFile> responseFiles = JsonConvert.DeserializeObject<List<APFile>>(response.Content, deserializationSettings);
                callback(responseFiles);
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

当然问题在于后端问题。代码是正确的!