Forum Xamarin.Forms

Wait for the Image to be uploaded

JassimRahmaJassimRahma USMember ✭✭✭✭

Hi,

I am using below to save a channel name and logo

I'd like to ask, using below code how can I make sure the photo was fully uploaded before showing the confirmation?

The problem here is when creating a new channel becauuse the file takes time to upload

but the bigger problem is when the user modify the channel because the Image control already has the existing umage and when updating it takes time which confuse the user and make him feel the image was not uploaded

var client = new HttpClient();

client.BaseAddress = new Uri("https://www.domain.com/save_media.php");

var content = new MultipartFormDataContent();

StreamImageSource streamImageSource = (StreamImageSource)viewModel.Image;
System.Threading.CancellationToken cancellationToken = System.Threading.CancellationToken.None;
Task<Stream> task = streamImageSource.Stream(cancellationToken);
Stream stream = task.Result;

var imageContent = new StreamContent(stream);
imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
content.Add(imageContent, "photo", "ChannelImage.png");

content.Add(new StringContent(TextBoxNewChannelName.Text), "\"channel\"");

var response = await client.PostAsync("https://www.domain.com/save_media.php", content);

/////// AFTER LOGO UPDLOADED ////////
Show Image on Image control
/////// AFTER LOGO UPDLOADED ////////

Thanks,
Jassim

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 2019

    Show ActivityIndicator before upload , remove it when uploading completed.

    //show ActivityIndicator
    var response = await client.PostAsync("https://www.domain.com/save_media.php", content);
    if(response.contains("successfully")){
        //remove ActivityIndicator
    }
    

    Or clear the image on image control and set it back until new image has been uploaded.

Sign In or Register to comment.