I am trying to download some files from my MAUI application. Application is built on a webView from where files should be downloaded. I have this logic in my DownloadListner:
public class CustomDownloadListener : Java.Lang.Object, IDownloadListener
{
public async void OnDownloadStart(string url, string userAgent, string contentDisposition, string mimetype, long contentLength)
{
try
{
DownloadManager.Request request = new DownloadManager.Request(global::Android.Net.Uri.Parse(url.Replace("blob:", "")));
request.SetMimeType(mimetype);
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
// if this path is not create, we can create it.
string thmblibrary = FileSystem.AppDataDirectory + "/download";
if (!Directory.Exists(thmblibrary))
Directory.CreateDirectory(thmblibrary);
request.SetDestinationInExternalFilesDir(global::Android.App.Application.Context, FileSystem.AppDataDirectory, "download");
DownloadManager dm = (DownloadManager)global::Android.App.Application.Context.GetSystemService(global::Android.App.Application.DownloadService);
dm.Enqueue(request);
}
catch(Exeption ex)
{
}
}
}
this works well for transferring most of the files in the app, but if the URL starts with the "blob:https://..." DownloadManager will throw an exception. I also tried to remove "blob:" from the URL in this case, the file gets downloaded but it is corrupted.
Is there any other way to transfer those files?