Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

FFImageLoading not showing images from LocalStorage in iOS

$
0
0

can I re-open this issue? I am using version 2.3.4 and I am not able to load the image saved in LocalStorage in iOS. The image Is saved in LocalStorage using PCLStorage and the local path looked like this
"/var/mobile/Containers/Data/Application/121745DA-AEED-4434-B105-91D1F755DDB5/Documents/../Library/16-03-10-2018-02-17-01_tn.jpg"

I have already checked if the file exists, and they do exists using PCLStorage CheckExistsAsync method.
The Source property by the way is binded in my model

I also added the prefix file:// but still not showing and also tried and alos tried using the ImageSourceConverter in FFImageLoading.Forms but no luck

Steps to Reproduce

Here's the code

async void SaveFile(byte[] data, string fileName, IFolder folder)
    {
        // create a file, overwriting any existing file  
        IFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

        // populate the file with image data  
        using (Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
        {
            stream.Write(data, 0, data.Length);
        }

        Logger.Write("file saved in " + file.Path);
    }

    // to use that method
    public async void SetVideoData(byte[] videoData, byte[] thumbnailData)
    {
        // well save the video and thumbnail in LocalStorage
        IFolder folder = FileSystem.Current.LocalStorage;

        var subFolderExists = await folder.CheckExistsAsync("VidsImages");

        if (subFolderExists == ExistenceCheckResult.NotFound)
        {
            folder = await folder.CreateFolderAsync("VidsImages", CreationCollisionOption.ReplaceExisting);
        }
        else
        {
            folder = await folder.GetFolderAsync("VidsImages");
        }

        // fix PCLStorage bug
        //string localStorage = folder.Path.Replace("/../Library", null);

        // send video and thumbnail to the server

        // TODO: .mov is for iOS
        // must know if the videoData came from Android or iOS
        string video_filename = GenerateFilename(".mov");
        SaveFile(videoData, video_filename, folder);

        string tn_filename = GenerateFilename("_tn.jpg");
        SaveFile(thumbnailData, tn_filename, folder);

        DataStore_Moments.MomentsCollection.Add(new Models.Model_Moments()
        {
            Id = Guid.NewGuid().GetHashCode(),
            ImageVideoPath = Path.Combine(folder.Path, video_filename),
            ThumbnailPath = Path.Combine(folder.Path, tn_filename),
            MomentType = Models.Enum_MomentType.VIDEO,
            DateCreated = DateTime.Now
        });
        DataStore_Moments.SaveSettings();
    }

    // in my ViewModel where the Moments collection in data store passed in my ObservableCollection
    MomentsCollection.Clear();
    foreach (Model_Moments m in DataStore_Moments.MomentsCollection)
    {
        IFolder folder = FileSystem.Current.LocalStorage;
        folder = folder.GetFolderAsync("VidsImages").Result;
        string filename = Path.GetFileName(m.ThumbnailPath);
        ExistenceCheckResult exists = await folder.CheckExistsAsync(filename);
        if(exists == ExistenceCheckResult.FileExists)
        {
            // fix PCLStorage bug
            //string localStorage = m.ThumbnailPath.Replace("../", null);

            string localStorage = new Uri(m.ThumbnailPath).AbsolutePath;
            localStorage = "file://" + localStorage;

            m.ThumbnailPath = localStorage;
            MomentsCollection.Add(m);
        }
    }

    // now using it in XAML
    <!--#region moments history-->
    <Grid Grid.Row="2" HeightRequest="150">
        <ScrollView Orientation="Horizontal">
            <ctl:RepeaterView Orientation="Horizontal" ItemsSource="{Binding Moments.MomentsCollection}">
                <ctl:RepeaterView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ff:CachedImage Source="{Binding ThumbnailPath}" HeightRequest="130" Margin="5,0" CacheType="Disk" DownsampleToViewSize="True">
                                <ff:CachedImage.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding BindingContext.Moments.Command_SelectMoment, Source={Reference This}}" CommandParameter="{Binding }" />
                                </ff:CachedImage.GestureRecognizers>
                            </ff:CachedImage>
                        </ViewCell>
                    </DataTemplate>
                </ctl:RepeaterView.ItemTemplate>
            </ctl:RepeaterView>
        </ScrollView>
    </Grid>
    <!--#endregion-->

Expected Behavior

Image should be loading as expected and reported here
https://github.com/luberda-molinet/FFImageLoading/issues/423#issue-196241695

Actual Behavior

Image does not loaded in given local path

Basic Information

Screenshots


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>