将映像上传到Azure云部署的应用程序时出现问题-Xamarin

时间:2019-04-03 08:40:39

标签: c# xamarin asp.net-web-api xamarin.android asp.net-web-api2

使用以下代码,我不断收到错误: 当我在本地IIS上发布此Web API并将映像从xamarin上传到服务器时,此代码运行良好,没有收到错误,但是在发布API Azure云时,我面临以下错误。如果有人知道,请帮助我

  

{状态代码:400,ReasonPhrase:“错误请求”,版本:1.1,内容:   System.Net.Http.StreamContent,标头:{缓存控件:无缓存   语法:无缓存服务器:Microsoft-IIS / 10.0 X-AspNet-版本:   4.0.30319 X-Powered-By:ASP.NET Set-Cookie:ARRAffinity = 7c5bdbe4510de6d1a2b16faa5f8c48d98b00f39fe983a5eac89ec12520de616b; Path = /; HttpOnly; Domain = mitsppk.azurewebsites.net   日期:2019年4月3日星期三07:28:08 GMT过期:-1内容长度:0}}

API代码:

public async Task<IHttpActionResult> Post()
        { 
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {              
                return BadRequest();
              }
            string PATH = HttpContext.Current.Server.MapPath("~/assets/ComplaintSystemApp/");           
            CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider(PATH);           
            List<string> files = new List<string>();

            try
            {                          
                foreach (MultipartFileData file in provider.FileData)
                {
                    files.Add(Path.GetFileName(file.LocalFileName));                 
                    newstreetLightComplaintImg.ImgPath = files[0];

                }


                return Ok();               
            }
            catch (System.Exception e)
            {
                return BadRequest();

            }
        }

从xamarin andriod上传图片:

     using (var client = new HttpClient())
        {
      var upfilebytes = File.ReadAllBytes(file);
                var fileContent = new ByteArrayContent(upfilebytes);
       fileContent.Headers.ContentType = 
       MediaTypeHeaderValue.Parse("application/octet-stream");
                fileContent.Headers.ContentDisposition = new 
             ContentDispositionHeaderValue("form-data")
                {
                    Name = "file",
                    FileName = "abc.png"
                };
                string boundary = "---8d0f01e6b3b5dafaaadaad";
  MultipartFormDataContent multipartContent = new 
               MultipartFormDataContent(boundary);
                multipartContent.Add(fileContent);
            var response = await 
 client.PostAsync("http://IPaddress/website/api/Img",multipartContent);
     var responsestr = response.Content.ReadAsStringAsync().Result;
  }

0 个答案:

没有答案