public static void UseProviderStorage(this IApplicationBuilder builder, BTCPayServerOptions options) { var dir = FileSystemFileProviderService.GetStorageDir(options); DirectoryInfo dirInfo; if (!Directory.Exists(dir)) { dirInfo = Directory.CreateDirectory(dir); } else { dirInfo = new DirectoryInfo(dir); } builder.UseStaticFiles(new StaticFileOptions() { ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"), FileProvider = new PhysicalFileProvider(dirInfo.FullName), OnPrepareResponse = context => { if (context.Context.Request.Query.ContainsKey("download")) { context.Context.Response.Headers["Content-Disposition"] = "attachment"; } } }); }
public static void UseProviderStorage(this IApplicationBuilder builder, BTCPayServerOptions options) { try { var dir = FileSystemFileProviderService.GetStorageDir(options); var tmpdir = FileSystemFileProviderService.GetTempStorageDir(options); DirectoryInfo dirInfo; if (!Directory.Exists(dir)) { dirInfo = Directory.CreateDirectory(dir); } else { dirInfo = new DirectoryInfo(dir); } DirectoryInfo tmpdirInfo; if (!Directory.Exists(tmpdir)) { tmpdirInfo = Directory.CreateDirectory(tmpdir); } else { tmpdirInfo = new DirectoryInfo(tmpdir); } builder.UseStaticFiles(new StaticFileOptions() { ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"), FileProvider = new PhysicalFileProvider(dirInfo.FullName), OnPrepareResponse = context => { if (context.Context.Request.Query.ContainsKey("download")) { context.Context.Response.Headers["Content-Disposition"] = "attachment"; } } }); builder.UseStaticFiles(new StaticFileOptions() { ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}tmp"), FileProvider = new TemporaryLocalFileProvider(tmpdirInfo, dirInfo, builder.ApplicationServices.GetService <StoredFileRepository>()), OnPrepareResponse = context => { if (context.Context.Request.Query.ContainsKey("download")) { context.Context.Response.Headers["Content-Disposition"] = "attachment"; } } }); } catch (Exception e) { Logs.Utils.LogError(e, $"Could not initialize the Local File Storage system(uploading and storing files locally)"); } }
public static void UseProviderStorage(this IApplicationBuilder builder, BTCPayServerOptions options) { var dir = FileSystemFileProviderService.GetStorageDir(options); DirectoryInfo dirInfo; if (!Directory.Exists(dir)) { dirInfo = Directory.CreateDirectory(dir); } else { dirInfo = new DirectoryInfo(dir); } builder.UseStaticFiles(new StaticFileOptions() { ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"), FileProvider = new PhysicalFileProvider(dirInfo.FullName) }); }