如果我通过 Insomnia 将图像上传到我的 Laravel 应用程序,一切正常,我得到以下日志
[2020-03-04 05:26:39] local.DEBUG: array (
'image' =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'Screenshot_1583210368.png',
'mimeType' => 'image/png',
'error' => 0,
'hashName' => NULL,
)),
)
但是,如果我在 android 模拟器上上传图像,Laravel 中的日志文件看起来像(1000 多行):
�"@�G����ޠ��U��H��I�G"Ĉ`.SB^G
这是我的 Xamarin 函数:
public async Task<string> uploadImage(Stream stream)
{
using (var client = new HttpClient())
{
var content = new MultipartFormDataContent();
content.Add(new StreamContent(stream),"image");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (Application.Current.Properties["access_token"].ToString()));
var result = await client.PostAsync("https://example.com/api/upload/image", content);
return "";
}
}