0

I am creating an application that download and upload attachment from the Xamarin.Forms application.

I am using .Net standard project and try to use with the "CrossDownloadManager" Nuget but it is not compatible and other reference for download file are using url but in this situation I have base64byte string.

I also try with This reference but it doesn't work for me.

Application works on Android and iOS.

I attached sample response Here: Response Image

Can anyone look into this and suggest me what should I have to do in that?

Deep Soni
  • 431
  • 4
  • 24
  • Are you saying you already have the base64 data in your app and you need to decode it? – Jason May 23 '19 at 13:24
  • @Jason Thanks for reply. Yes I get string data that are in `base64` and I have to decode that and than I have to download that file like `Sample.txt.` with original content. – Deep Soni May 23 '19 at 13:26
  • so the base64 string contains the url for the file you need to download? – Jason May 23 '19 at 13:30
  • No base64 string contains Filedata I add you sample json please check that. – Deep Soni May 23 '19 at 13:44
  • "download" typically means to transfer a file/data from a remote server to your local system. If you already have the data locally, then you do not need to "download" it, and your repeated use of that term is incredibly confusing. – Jason May 23 '19 at 13:49
  • @Jason Yes That's true but for a security reason we save file in Base64 string On click of download I have to return to that file and that I have to save that on user's device. – Deep Soni May 23 '19 at 13:55
  • As best as I can tell there are three things involved here. 1) download a file (does NOT matter what kind) from a remote server, 2) decode base64 data, 3) save the data on the user's device. Which of those three steps do you not understand how to do? – Jason May 23 '19 at 14:02
  • I am not understand after first step I have Filename, Mimetype and also Decoded64 data but I don't know how to download that on user's device. Can you please guide me? – Deep Soni May 23 '19 at 14:04

1 Answers1

0
  1. download a file given a url

    var client = new HttpClient();
    var data = await client.GetStringAsync(url);
    
  2. if data is Base64, decode it

    var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
    var decoded = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
    
  3. save decoded string

    File.WriteAllText(filepath, decoded);
    
Jason
  • 86,222
  • 15
  • 131
  • 146
  • Thanks for answer. It helps me to get whole file in decrypted mode but I am still confuse that how I get `File Path` of end user. If I give fixed Path of `/Download` than it gives me an error. Can you please help me to solve that? – Deep Soni May 24 '19 at 04:40
  • https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/files?tabs=macos – Jason May 24 '19 at 13:45