Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to download File from api where api sends stream of file using cross file download manager?

$
0
0

Hello to all,
I was trying to download file in xamarin forms so I made API that could get those file. My API converts file into memory stream and same stream is sent in response(code is also attached). In xamarin.forms I have used xam.plugins.downloadmanager to download file. The file downloaded successfully but when opening the file, the stream of file are shown instead of the original file? If anyone knows to send the file instead of its stream from API then please help!
**[HttpGet]
public HttpResponseMessage GetFinalFile([FromUri] string fileName)
{
string filePath = string.Concat(@D:\TestShareFiles\, fileName);

        HttpResponseMessage response = new HttpResponseMessage();

        if (!File.Exists(filePath))
        {
            response.StatusCode = HttpStatusCode.NotFound;
            return response;
        }

        MemoryStream responseStream = new MemoryStream();
        Stream fileStream = File.Open(filePath, FileMode.Open);

        fileStream.CopyTo(responseStream);
        fileStream.Close();
        responseStream.Position = 0;


        response.StatusCode = HttpStatusCode.OK;
        response.Content = new StreamContent(responseStream);
        return response;
    }**

Viewing all articles
Browse latest Browse all 89864

Trending Articles



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