Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

[question] File download handling over mobile web apps. #220

Closed
arivera12 opened this issue Aug 8, 2020 · 5 comments
Closed

[question] File download handling over mobile web apps. #220

arivera12 opened this issue Aug 8, 2020 · 5 comments

Comments

@arivera12
Copy link

If a trigger a file download via JavaScript,

How does mobile web app handle this?

How does mobile web app handles a file download via content-disposition attachment header?

Do I will need to create a function which manage this and write to disk using the IXamarinBridge or this will auto trigger the save file dialog?

@arivera12 arivera12 changed the title [question] File download handling [question] File download handling over mobile web apps. Aug 8, 2020
@Daddoon
Copy link
Owner

Daddoon commented Aug 9, 2020

As Blazor is a SPA application, except if you do some custom implementation to mimic or handle a web server callback for the app, the easiest way in my opinion, not specially the fastest in term of performance, is to try to retrieve the selected file through JavaScript API after file selection, and then do whatever you want: Return this to Web C# context, or show it on the page directly if you need to, or transfer it to native.

With the JavaScript API you will get the data as text ideally (Base64) then send it to C# , then use a Proxy bridge to send the content to native C#.

Bytes support may be supported at Blazor level, but not sure, same for the interop to native. So a Base64 string is still the safest solution atm.

@Daddoon
Copy link
Owner

Daddoon commented Aug 9, 2020

@arivera12
Copy link
Author

arivera12 commented Aug 9, 2020

I have a package for that. https://github.com/arivera12/BlazorDownloadFile

I will give it a try once I can run the project on android I will give feedback for this.

I wanna see how this behave on mobile device installed app if save file dialog gets popped out or if I need xamarin bridge to use the c# file write method.

@arivera12
Copy link
Author

arivera12 commented Aug 25, 2020

This won't work on BlazorMobile since it's sanboxed by the browser control.

We need to write directly to the device disk.

We need to separate those apis one for the browser and one for native xamarin.

@Daddoon
Copy link
Owner

Daddoon commented Aug 25, 2020

As you can also fetch your data through a file input in the web browser and redirect it to Javascript, you may use the default file input in order to retrieve data and then store it to native definitively.

But yes, you may redirect to a native call that open a File browser when clicking on a button.

It's as you wish in the end. I didn't have benchmarked the performance while using a pure web implementation if you need to redirect the data to store to native.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants