Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created December 24, 2017 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/defd1385c8bab6ee266f9c6b3bfcc501 to your computer and use it in GitHub Desktop.
Save jfversluis/defd1385c8bab6ee266f9c6b3bfcc501 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Threading.Tasks;
using pdfjs.Interfaces;
using pdfjs.iOS.PlatformSpecifics;
using Xamarin.Forms;
[assembly: Dependency(typeof(LocalFileProvider))]
namespace pdfjs.iOS.PlatformSpecifics
{
public class LocalFileProvider : ILocalFileProvider
{
private readonly string _rootDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "pdfjs");
public async Task<string> SaveFileToDisk(Stream stream, string fileName)
{
if (!Directory.Exists(_rootDir))
Directory.CreateDirectory(_rootDir);
var filePath = Path.Combine(_rootDir, fileName);
using (var memoryStream = new MemoryStream())
{
await stream.CopyToAsync(memoryStream);
File.WriteAllBytes(filePath, memoryStream.ToArray());
}
return filePath;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment