gridr
gridr

Reputation: 135

MvvmCross.Plugins.File: A Downloaded and locally stored image is not displayed in MvxImageView

I save an image from the internet like this:

public void SetSelectedConsultant(string consultantId)
{
    // ...

    var path = this.fileStore.PathCombine(App.IMAGES_FOLDER, App.SELECTED_CONSULTANT_IMAGE_FILENAME);

    if (this.fileStore.Exists(path))
    {
        this.fileStore.DeleteFile(path);
    }

    this.fileStore.EnsureFolderExists(App.IMAGES_FOLDER);

    this.GeneralAsyncLoad(
        App.SERVER_URL + App.CONSULTANT_FILE_NAME,
        stream =>
            {
                this.SaveConsultantImage(stream, path);
                this.mvxMessenger.Publish(new ConsultantUpdatedMessage(this));
            });
}

private void SaveConsultantImage(Stream stream, string path)
{
    var memoryStream = new MemoryStream();
    stream.CopyTo(memoryStream);
    byte[] pictureBytes = memoryStream.ToArray();

    this.fileStore.WriteFile(path, pictureBytes);
}

ConsultantUpdatedMessage is caught by my view model which will RaisePropertyChanged for ConsultantImageUrl. My other properties like ConsultantName etc. are refreshed correctly in the view, but the image refuses to show in the control:

<Mvx.MvxImageView
    android:scaleType="fitXY"
    android:layout_margin="5dp"
    android:layout_width="220dp"
    android:layout_height="wrap_content"
    local:MvxBind="ImageUrl ConsultantImageUrl" />

I checked if the file exists, usin fileStore.Exists, which results "true", but the file won't show up. Is it possible I save the picture the wrong way?

EDIT: As a how-to, I used this tutorial (https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-16-CollectABull-Part5). However, there they use a photo from the local album instead of downloading one.

Upvotes: 1

Views: 894

Answers (1)

gridr
gridr

Reputation: 135

I found the problem. The url was wrong and it downloaded another (none-image) file and saved it. So a file was existing there, but could not be displayed in the view because it was not an image.

Upvotes: 1

Related Questions