Base solution for your next web application
Open Closed

Download files with Xamarin App #6727


User avatar
0
Ricavir created

Hi,

I'm trying to download files with Xamarin App. Server side is ASPNET CORE version 5.1 (with Angular web client)

I've tried both solutions :

  1. Download from Flurl download method
  2. Download with CrossDownloadManager component (https://github.com/SimonSimCity/Xamarin-CrossDownloadManager)

As it is done on angular side, I send a request from Xamarin app to the server to store file on temporory folder. Then I send a request to FileController (DownloadTempFile method) to get the file.

I'm using this code to build url :

var url = ApiUrlConfig.BaseUrl + "File/DownloadTempFile?fileType=" + result.FileType + "&fileToken=" + result.FileToken + "&fileName=" + result.FileName;

When testing this, I'm able to download files from received HTTP response content but the file is not recognized by the system (tested on Android emulator) and can't be opened. When I try to download a basic image from an existing website url (or a pdf file), everything works like a charm. File is downloaded and can be opened...

Do you have any idea to fix that ?

Just another remark : tenancy is determined from subdomain on server side... but url doesn't mentioned it. I don't think that it is a problem as this request doesn't need to know about tenant.


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir,

    Is the DowmloadTempFile in yoru project similar to this one https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/Controllers/FileController.cs#L34 ? I believe it has been changed recently.

    Another question, is result.FileName contains the file extension (like: test.pdf) ?

  • User Avatar
    0
    Ricavir created

    Hi @ismcagdas,

    In fact, DowmloadTempFile has changed but output is always the same. Yes, result.FileName contains the file extension.

    I've made another test by trying to open the url from embedded webbrowser (in this case, it is chrome on android emulator). File is downloaded and can be opened.

    The problem cames from file type which is always set to application/octet-stream as default MIME type on server side. It is not a problem when client app is running on a webbrowser (webbrowser automatically converts file type relatively to the file extension). But it is a problem for a Xamarin app.

    I will change DowmloadTempFile controller to manage MIME type according to file extension and avoid this issue on xamarin side.

    I will keep you informed if this change as not fixed the issue.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @ricavir

  • User Avatar
    0
    alper created
    Support Team

    set your mime-type to application/pdf