简体   繁体   English

使用xam.plugin.media将映像上传到服务器(后端)时收到错误请求

[英]Am getting Bad Request while uploading an Image to the server (backend) , am using xam.plugin.media

Am trying to upload an image with the help of Xam.plugin.media NuGet package. 我正在尝试借助Xam.plugin.media NuGet包上传图像。 But am getting a 400 Bad Request . 但是却收到了400错误请求

Below is my method which uploads the image to the backend. 下面是我的方法,将图像上传到后端。

private async void UploadImage()
        {
            var token = Application.Current.Properties["token"].ToString();


            var multiForm = new MultipartFormDataContent();


            var imagFile = _mediaFile.AlbumPath;
            var upfilebytes = File.ReadAllBytes(imagFile);
            ByteArrayContent baContent = new ByteArrayContent(upfilebytes);

            multiForm.Add(new StringContent("1"), "x");
            multiForm.Add(new StringContent("100"), "y");
            multiForm.Add(new StringContent("100"), "width");
            multiForm.Add(new StringContent("100"), "height");


            multiForm.Add(baContent, "file", Path.GetFileName(_mediaFile.AlbumPath));

            var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6" +
                "IkpXVCJ9.eyJYwZi05MjhhLTRiZjctYjZkNi0wY2U1ODRkOGRjZmQiLCJ1bmlxdWVfbmFtZ" +
                "SI6IjIwZDA0MDY3LTU3YzYtNGY2MC04ZDI5LTg1NzkxMmFmOWI2MSIsImNsdCI6ImVuLUdCIiwidHoiOiJ" +
                "XLiBFdXJvcGUgU3RhbmRhtZSIsIm5iZiI6MTU1NjQ3NTMyNCwiZXhwIjoxNTU2NDgyNTI0LCJpY" +
                "XQiOjE1NTY0NzUzMjQsImlzcyI6Imh0dHBzOi8vYXBpLnZpYS5zb2Z0d2FyZSIsImF1ZCI6Imh0dHBz" +
                "Oi8vd3d3LnZpYS5zb2Z0d2FyZSJ9.z5rghA338FDAtoInFYugMgwIirrdl9CrsGKhS8ceoFI");
            var response = await client.PostAsync(utils.Settings.BaseUrl + "/auth/Users/ChangeAvatar", multiForm);

            Debug.WriteLine("--> * "+response.Content.ReadAsStreamAsync().Result);

            Debug.WriteLine("response --> * "+_mediaFile.AlbumPath);
            Debug.WriteLine("--> * " + response);
        }

So according to what I have implemented, I thought everything could work out. 因此,根据我所实施的方法,我认为一切都可以解决。

Below are the parameters needed by the backend, actually when I try testing the endpoint in postman it works fine, but the method above doesn't work. 以下是后端所需的参数,实际上,当我尝试在邮递员中测试端点时,它可以正常工作,但是上述方法不起作用。

在此处输入图片说明

This is what happens on postman everything works fine when I upload an image. 这就是邮递员上载的情况,当我上传图像时一切正常。

在此处输入图片说明

What could be missing in my code for uploading? 上传代码中可能缺少什么?

服务需要一个名为“ image”的参数,但是您要传递一个名为“ file”的参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Xam.Plugin.Media 从图片库中添加照片? - How to add photo from gallery in Image with Xam.Plugin.Media? 无法使用Xam.Plugin.Media插件 - Can't use Xam.Plugin.Media plugin 尝试使用Xam.Plugin.Media打开相机时抛出异常 - Exception throw out when trying to open the camera using Xam.Plugin.Media 使用 Xam.Plugin.Media 拍摄和存储用户照片的强制性要求 - Compulsary requirement to take and store users photo using Xam.Plugin.Media Xam.Plugin.Media的方法“ TakePhotoAsync”在Xamarin.Forms的平台WinPhone上返回null - Method “TakePhotoAsync” of Xam.Plugin.Media return null on platform WinPhone in Xamarin.Forms Xamarin Forms 和 xam.plugin.media:无法解析对 Xamarin.Essentials.Permissions 的引用 - Xamarin Forms and xam.plugin.media: could not resolve reference to Xamarin.Essentials.Permissions 将来自 Xam.Plugin.Media 5.0.1 的 imageSource 转换为 Xamarinforms 中的字节数组? - Convert imageSource coming from Xam.Plugin.Media 5.0.1 to byte array in Xamarinforms? 在 Angular 和 .Net 核心项目中上传图像时出现错误 415 - I am getting Error 415 while uploading image in Angular and .Net core project 我正在尝试使用 c# 从 Twitter api 获取请求令牌,但收到 400 个错误的请求错误 - I am trying to get request token from Twitter api using c#, but getting 400 bad request error 使用带有C#后端的HTML5.0将图像上传到服务器 - uploading image to server using HTML5.0 with c# backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM