Angular 8将包含图像和文本的表单数据发送到.Net Core 2.2 Api,给出415不支持的媒体类型

问题描述 投票:0回答:1

This is a sniped from my angular component .ts code where i make my request

This is a sniped from the service function that execute the http request

每次我提出请求时,都会出现错误,显示:http://192.168.1.24:2502/SocialNetwork/Posts/CreatePost的Http错误响应:415不支持的媒体类型

And this is the network tab for a request i made

请任何人可以帮助我吗?

angular asp.net-core httprequest image-uploading media-type
1个回答
0
投票
在发送图像之前,请确保将图像转换为Base64,因此:

getBase64(event) { let file = event.target.files[0]; let reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function () { console.log(reader.result); // This is the actual result of converting your image to base64 }; reader.onerror = function (error) { console.log('Error: ', error); }; }

以及您的.html

<input type="..." (change)="getBase64($event)">

© www.soinside.com 2019 - 2024. All rights reserved.