parmendra kumar

parmendra kumar

  • NA
  • 113
  • 5k

How to receive photo to all device in chat app

Mar 28 2018 4:27 AM
I am working a chat application and when I upload a image with button click then image doesn't received to another device only sender device showing it.
 
MyButton click code:
  1. public async void Image_Clicked(object sender, EventArgs e)  
  2. {  
  3. try  
  4. {  
  5. file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions  
  6. {  
  7. CompressionQuality = 50, PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium });  
  8. FileName = file.Path;  
  9. FileName = FileName.Substring(FileName.LastIndexOf("/") + 1);  
  10. var content = new MultipartFormDataContent();  
  11. //IFolder rootFolder = await FileSystem.Current.GetFolderFromPathAsync(FileName);  
  12. //var filee = await rootFolder.GetFileAsync(filename2);  
  13. //Stream stream = await filee.OpenAsync(FileAccess.Read);  
  14. content.Add(new StreamContent(file.GetStream()), "\"file\"", $"\"{file.Path}\"");  
  15. byteData = Model.Convert.ToByteArray(FileName);  
  16. var im = ImageSource.FromStream(this.file.GetStream);  
  17. using (var memoryStream = new MemoryStream())  
  18. {  
  19. activityIndicator.IsRunning = true;  
  20. file.GetStream().CopyTo(memoryStream);  
  21. file.Dispose();  
  22. //  
  23. return memoryStream.ToArray();  
  24. uploadedFilename = await AzureStorage.UploadFileAsync(ContainerType.Image, new MemoryStream(memoryStream.ToArray()));  
  25. }  
  26. if (!string.IsNullOrWhiteSpace(uploadedFilename))  
  27. {  
  28. var imageData = await AzureStorage.GetFileAsync(ContainerType.Image, uploadedFilename);  
  29. var img = ImageSource.FromStream(() => new MemoryStream(imageData));  
  30. TextContainer.Add(new MessageText { imgsource = img });  
  31. activityIndicator.IsRunning = false;  
  32. }  
  33. }  
  34. catch( Exception ex)  
  35. {  
  36. System.Diagnostics.Debug.WriteLine(ex);  
  37. }  
  38. }  

Answers (1)