-- xamarin forms code--
public async void uploadimgAsync()
{
String pathofFile
="/mnt/sdcard/Android/data/com.companyname.Lastappforcamera
/files/Pictures/Sample/testone.jpg";
using (var streamReader = new StreamReader(pathofFile))
{
var bytes = default(byte[]);
using (var memstream = new MemoryStream())
{
streamReader.BaseStream.CopyTo(memstream);
bytes = memstream.ToArray();
}
ax = bytes;
}
String URI = "xxxxxxxxx";
await CrossFileUploader.Current.UploadFileAsync(URI, new
FileBytesItem("POST", ax, "testone.jpg"), new Dictionary<string,
string>()
{
{"<HEADER KEY HERE>" , "<HEADER VALUE HERE>"}}
);
}
--- web service method---
[WebMethod]
public String SaveDocumentPictureForXamarin(Byte[]
ImageByteArray,string ImageName)
{
string DocumentPath = Server.MapPath("~/Upload\\documents\\");
if (!(Directory.Exists(DocumentPath)))
{
Directory.CreateDirectory(DocumentPath);
}
DocumentPath += ImageName;
FileStream objfilestream = new FileStream(DocumentPath,
FileMode.Create,FileAccess.ReadWrite);
objfilestream.Write(ImageByteArray, 0, ImageByteArray.Length);
objfilestream.Close();
return "success";
}
内容类型:application / x-www-form-urlencoded
请帮我将图像作为bytearray上传到网络服务。我无法获取要上传的代码。我试过httpclient,它显示了web方法错误。我需要传递图像名称和imagebytearray。我是xamarin的新手。