Sujeet Raman

Sujeet Raman

  • 798
  • 915
  • 333.2k

Unable to find OpenReadstream in image upload functionality in blazor

Feb 1 2023 9:32 AM

Hi, I am trying to get image URL from selected images. The challenge I am facing here is I am not supposed to touch the  OnFilesChanged method directly. I need to create a separate class and access the original class items. How I can get image URL of each selected files in to a separate class list(my own class) I don't know this is the correct approach if not please suggest one

.below is my inaccessible method and inaccessible class Browsedfileclass 

private async Task OnFilesChanged(InputFileChangeEventArgs eventArgs)
{
    var files = new List<Browsedfileclass>(eventArgs.FileCount);
    files.AddRange(eventArgs.GetMultipleFiles(10000).Select(file => new Browsedfileclass(file)));
}

so I have created a separate class like below

public class Myclass
{
    private Browsedfileclass file;

    public Myclass(Browsedfileclass file)
    {
        File = file;
        this.file = file;
        Name = file.FileName;
        ContentType = file.File.ContentType;
        FileNameWithoutExtension = file.FileNameWithoutExtension;
        Size = File.File.Size;

        var image =  File.File.RequestImageFileAsync("image/png", 100, 100);
        var buffer = new byte[Size];
        image.OpenReadStream().ReadAsync(buffer);//here i am getting error that OpenReadStream //doesnot contain
        ImageDataUrl = $"data:{"image/png"};base64,{Convert.ToBase64String(buffer)}";
    }
}

 


Answers (3)