这是我如何获取字节数组和数组类型以及我如何发送对象
public partial class Addprofilepicture : ContentPage
{
ImageButton imagebutton;
Label basse64;
IMyAPI myAPI;
APIRequestHelper apiRequestHelper;
public Addprofilepicture()
{
InitializeComponent();
imagebutton = this.FindByName<ImageButton>("addprofilepicture");
basse64 = this.FindByName<Label>("base64");
myAPI = RestService.For<IMyAPI>("http://10.0.2.2:8080");
apiRequestHelper = new APIRequestHelper(myAPI);
}
private async void addprofilepicture_Clicked(object sender, EventArgs e)
{
Stream stream = await DependencyService.Get<IPhotoPickerService>().GetImageStreamAsync();
if (stream != null)
{
ImageSource Image;
byte[] b = ReadFully(stream);
String s = Convert.ToBase64String(b);
Image = Xamarin.Forms.ImageSource.FromStream(
() => new MemoryStream(Convert.FromBase64String(s)));
imagebutton.Source = Image;
basse64.Text = s;
Postbase(b);
}
}
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
public async void Postbase(byte[] bytearray) {
base64s s = new base64s()
{
base64string = bytearray
};
// string stringpayload = JsonConvert.SerializeObject(s);
await myAPI.PostProfilePhoto(s);
}
public class base64s {
public byte[] base64string { get; set; }
}
}
它几乎需要一两分钟,所以我认为必须有一种更快的方式来发送它这里是 post 方法
[Post("/Phototest")]
Task<string> PostProfilePhoto(base64s s);
这是节点js代码
app.post('/Phototest', (request, response) =>{
console.log('request tried');
REQUEST_BODY = request.body;
console.log(REQUEST_BODY.base64string);
});
控制台(我正在显示,因为我不确定这是否是一个字节 [] 应该是什么样子)。(它需要永远)我是新的并且想知道如何使这个发布过程更快并且不会失败,因为它花费了太长时间。