here is how i get the byte array and the type of array and how i send the object
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; }
}
}
it take almost a whole minute or two so i assume there must be a faster way to send it here is the post method
[Post("/Phototest")]
Task<string> PostProfilePhoto(base64s s);
here is the node js code
app.post('/Phototest', (request, response) =>{
console.log('request tried');
REQUEST_BODY = request.body;
console.log(REQUEST_BODY.base64string);
});
the console (im showing because im not sure if this is what a byte[] should look like).(it takes forever) im new and wondering hoe to make this posting process quicker and not fail becasue its taking too long.