Saturday, October 17, 2026
HomeiOS DevelopmentBlazor Wasm Take Phote on IOS

Blazor Wasm Take Phote on IOS

[ad_1]

In my Blazor web site i am calling the digital camera utilizing this code:

<InputFile 
    id="imageSelect" 
    identify="imageSelect" 
    OnChange="@UploadImage" 
    seize="digital camera" 
    sort="file" 
    settle for="picture/*"/>

If a run the this blazor web page (containing this code), the Iphone digital camera pops up. In order that works and if I take an image it would load in my Picture:

<img class="card-img-top img-fluid" 
    src="@((IsahImageEntity.Picture != null) ? utils.GetImage(IsahImageEntity.Picture) : (ImageChanging ? "" : "img/no-camera-sign.jpg"))" 
    alt=""
/>  

So the UploadImage operate wil Add the picture into the database and likewise set this Picture property: IsahImageEntity.Picture

However generally it does not work the web page is robotically reloaded and the Photograph (taken by the digital camera) is not uploaded to the database and it is not proven within the Img html part.

Right here is the UploadImage operate:

        protected async Job UploadImage(InputFileChangeEventArgs e)
        {
            ShowSpinner = true;
            ImageChanging = true;

            StateHasChanged();

            //Take away the outdated image...
            var oldImage = IsahImageEntity!.Picture;
            IsahImageEntity.Picture = null;

            //get the file
            var file = e.File;

            var newFile = await e.File.RequestImageFileAsync("picture/png", 300, 300);
            IsahImageEntity.Picture = await File2ByteArray(newFile);
            if (ForImaging)
            {
                var bln = await SaveInDB(newFile);

                if (!bln)
                {
                    //reset the outdated Picture
                    IsahImageEntity!.Picture = oldImage;
                }
            }
            else
            {
                await SaveDocumentInDB(newFile);
            }

            ShowSpinner = false;
            ImageChanging = false;
        }

        personal async Job<byte[]> File2ByteArray(IBrowserFile file)
        {
            byte[] bytes = new byte[file.Size];

            await file.OpenReadStream(file.Dimension).ReadAsync(bytes);
            
            return bytes;
        }

Anybody who acknowledges this behaviour? And is there an answer. So why does the web page generally reload as an alternative of displaying the taken picture?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments