Question about adding images

Hi

I just tried your demo in

https://github.com/SyncfusionExamples/How-to-attach-image-from-gallery-in-Xamarin.Forms-chat

When I add multiple images and scroll up and down, all images I just uploaded are shown with the last image uploaded.

Why does this happend?

How can select multiple images at once?

Do you have an example where I can view the chat information in a database?

thanks in advance...

5 Replies 1 reply marked as answer

SS Sivaraman Sivagurunathan Syncfusion Team July 31, 2020 06:12 AM UTC

Hi jose, 

Thanks for using Syncfusion controls. 

Regarding your image restored issue when scrolling. 

We are able to reproduce the reported issue from our side. . Currently we are validating the issue we will  update the further details on or before 4th August 2020. We appreciate your patience until then.  

Regarding multiple message: 

You can able to achieve your requirement by sample level. We have prepared the sample based on you requirement and attached for reference. You can download the same from the below link. 


protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) 
{ 
    if ((requestCode == ImageHelper.PickImageId) && (resultCode == Result.Ok) && (data != null)) 
    { 
        if (data.ClipData.ItemCount > 0) 
        { 
            for (int i = 1; i <= data.ClipData.ItemCount- 1; i++) 
            { 
                ClipData.Item item = data.ClipData.GetItemAt(i); 
                ImageHelper.uri[i] = item.Uri; 
            } 
        } 
    } 
    base.OnActivityResult(requestCode, resultCode, data); 
    ImageHelper.returnedFromImageActivity = true; 
} 
 
public Task<bool> StartImageChooser() 
{ 
    Intent = new Intent(); 
    Intent.SetType("image/*"); 
    Intent.SetAction(Intent.ActionGetContent); 
    Intent.PutExtra(Intent.ExtraAllowMultiple, true); 
    (ImageHelper.context as MainActivity).StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), ImageHelper.PickImageId); 
    return Task.Run(() => CheckIfImageChooserActivityIsExited()); 
 
} 



Please refer the following blog and video to get the chat information in a database


Regards, 
Sivaraman S 




SS Sivaraman Sivagurunathan Syncfusion Team August 4, 2020 05:20 PM UTC

Hi jose, 

Due to the complexity, we are still validating the issue. we will  update the further details on or before 6th August 2020. We appreciate your patience until then.   

Regards, 
Sivaraman S 



SS Sivaraman Sivagurunathan Syncfusion Team August 6, 2020 07:04 AM UTC

Hi Jose,  

Thanks for your patience. 

After the deep analyses, this issue not related to the SfChat control. we can overcome the issue by Convert the Stream to a byte array and then back to a stream from that new byte array. We have modified the sample for you reference you can download the same from the below link. 


ImageMessage ImageMessage; 
private void createMessage(Stream stream) 
{ 
    ImageMessage = new ImageMessage(); 
    ImageMessage.Aspect = Aspect.Fill; 
    byte[] imageBytes = ReadFully(stream); 
    ImageMessage.Source = Xamarin.Forms.ImageSource.FromStream(() => new MemoryStream(imageBytes)); 
    ImageMessage.Author = this.ViewModel.CurrentUser; 
    this.ViewModel.Messages.Add(ImageMessage); 
} 
 
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(); 
    } 
} 




Please refer the following thread: 

Regards,  
Sivaraman S  


Marked as answer

JL jose luis barajas August 14, 2020 05:27 PM UTC

Thanks!!!
works perfect!


SS Sivaraman Sivagurunathan Syncfusion Team August 17, 2020 04:02 AM UTC

Hi Jose, 

We are happy to hear from you. Please get in touch with us if you would require any further assistance.   
  
Regards,   
Sivaraman S   


Loader.
Up arrow icon