我必须将我的应用程序中的图像上传到php web服务我试过这段代码:
private void upload(MediaFile mediaFile)
{
try
{
byte[] data = ReadFully(mediaFile.Source);
var imageStream = new ByteArrayContent(data);
imageStream.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = Guid.NewGuid() + ".Png"
};
var multi = new MultipartContent();
multi.Add(imageStream);
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri("url");
var result = client.PostAsync("api/ManageImage", multi).Result;
}
catch (Exception e)
{
}
}
PHP:
<?php
$uploads_dir = 'Image/'; //Directory to save the file that comes from
client application.
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
?>
我使用Xam.Plugin.FilePicker获取文件,但我不知道如何发送以及如何重新获取图像