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(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)}";
}
}
Tuhin PaulPosted Mar 6, 2023, 1:26 AM
I think the main reason you are getting an error in this line of code:
is that you are trying to create a new list of type "Myclass" using the length property of the "files" list which is of type "List".
To fix this error, you can simply replace "Myclass" with "Browsedfileclass" like this:
This will create a new list of type "Browsedfileclass" with the count of items in the "files" list.
Remember that the namespace for your "IBrowsedFile" interface is imported in your code file.
Sujeet RamanPosted Feb 2, 2023, 5:03 AM
I need to keep below lines anyway
Getting error here
Naimish MakwanaPosted Feb 1, 2023, 11:42 AM
Hello Sujit,
Please change your code as below and try.
Thanks
Naimish