Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Cannot upload images to Blazor app with Android

$
0
0

I have an application where users can upload images from their device (mobile or desktop). For desktop users, it works fine. For most mobile users (iOS, older android), it also works fine. But I have a user with a newer Samsung Fold phone whose images fail to upload with the following error:

[11:05:28 ERR] Unable to complete ScaleImageWithThumbnailSystem.InvalidOperationException: An error occurred while reading the remote stream: NotReadableError: The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSDataStream.ReceiveData(Int64 chunkId, Byte[] chunk, String error)   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)   at System.IO.Pipelines.Pipe.GetReadAsyncResult()   at System.IO.Pipelines.PipeReaderStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSDataStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)   at Microsoft.AspNetCore.Components.Forms.BrowserFileStream.CopyFileDataIntoBuffer(Memory`1 destination, CancellationToken cancellationToken)   at Microsoft.AspNetCore.Components.Forms.BrowserFileStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)   at System.IO.Stream.<CopyToAsync>g__Core|27_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken)   at RedactedApp.Infrastructure.Services.ImageProcessing

All the users are using Microsoft Edge browser, both for mobile and desktop.

The main logic looks like this:

public async Task<ScalingResponse> ScaleImageWithThumbnail(Stream inputData, Stream primaryOutputData, Stream thumbnailOutputData, int maxWidth, int thumbnailWidth){    var response = new ScalingResponse();    try    {        // NOTE: Resize primary source stream        using var inputCopy = new MemoryStream();        await inputData.CopyToAsync(inputCopy);        inputCopy.Seek(0, SeekOrigin.Begin);        MagicImageProcessor.ProcessImage(inputCopy, primaryOutputData, new ProcessImageSettings() { Width = maxWidth, ResizeMode = CropScaleMode.Max});        // ... snip ...    }    catch (Exception ex)    {        _logger.LogError(ex, "Unable to complete ScaleImageWithThumbnail");        response.Success = false;        response.Message = "Unable to process image. See log for details";    }    return response;}

The streams of image data come from a list of IBrowserFile when the user selects files from a dialog.

private async Task SelectFiles(InputFileChangeEventArgs e){    _hasExceededFileLimit = false;    try    {        _files = e.GetMultipleFiles(5).ToList();        foreach (var file in _files)        {            try            {                // Add attachment placeholder                var placeholder = ImageAttachmentModel.Create(Model.BillId, file.Name, file.ContentType, file.Size);                Model.Attachments.Add(placeholder);                // Upload file and generate thumbnail                ProcessAndUploadResponse response;                await using (var fileStream = file.OpenReadStream(100000000L, CancellationToken.None))                {                    response = await Mediator.Send(new ProcessAndUploadCommand(Model.BillId, ImageDataModel.Create(file.Name, file.ContentType, file.Size, fileStream), Options.Value.AttachmentMaxImageWidth));                }                // Update placeholder to contain meaningful data                placeholder.Update(response);            }            // ... snip ...        }    }    // ... snip ...}

I'm wondering if there's some way I am retrieving or manipulating the streams that Android doesn't like. However, I am pretty confused by the different behavior between devices.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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