1- using OnnxStack . Web . Models ;
1+ using Microsoft . AspNetCore . Hosting . Server . Features ;
2+ using OnnxStack . Web . Models ;
23using OnnxStack . WebUI . Models ;
34using System . Text . Json ;
45using System . Text . Json . Serialization ;
@@ -10,16 +11,18 @@ public class FileService : IFileService
1011 private readonly ILogger < FileService > _logger ;
1112 private readonly IWebHostEnvironment _webHostEnvironment ;
1213 private readonly JsonSerializerOptions _serializerOptions ;
14+ private readonly IServerAddressesFeature _serverAddressesFeature ;
1315
1416 /// <summary>
1517 /// Initializes a new instance of the <see cref="FileService"/> class.
1618 /// </summary>
1719 /// <param name="logger">The logger.</param>
1820 /// <param name="webHostEnvironment">The web host environment.</param>
19- public FileService ( ILogger < FileService > logger , IWebHostEnvironment webHostEnvironment )
21+ public FileService ( ILogger < FileService > logger , IWebHostEnvironment webHostEnvironment , IServerAddressesFeature serverAddressesFeature )
2022 {
2123 _logger = logger ;
2224 _webHostEnvironment = webHostEnvironment ;
25+ _serverAddressesFeature = serverAddressesFeature ;
2326 _serializerOptions = new JsonSerializerOptions { WriteIndented = true , Converters = { new JsonStringEnumConverter ( ) } } ;
2427 }
2528
@@ -155,9 +158,11 @@ public Task<string> UrlToPhysicalPath(string url)
155158 /// <param name="folder">The folder.</param>
156159 /// <param name="file">The file.</param>
157160 /// <returns></returns>
158- public Task < string > CreateOutputUrl ( string file )
161+ public Task < string > CreateOutputUrl ( string file , bool relative = true )
159162 {
160- return Task . FromResult ( $ "/images/results/{ file } ") ;
163+ return relative
164+ ? Task . FromResult ( $ "/images/results/{ file } ")
165+ : Task . FromResult ( $ "{ GetServerUrl ( ) } /images/results/{ file } ") ;
161166 }
162167
163168
@@ -169,6 +174,17 @@ public Task<string> CreateRandomName()
169174 {
170175 return Task . FromResult ( Path . GetFileNameWithoutExtension ( Path . GetRandomFileName ( ) ) ) ;
171176 }
177+
178+
179+ private string GetServerUrl ( )
180+ {
181+ var address = _serverAddressesFeature . Addresses . FirstOrDefault ( x=> x . StartsWith ( "https" ) )
182+ ?? _serverAddressesFeature . Addresses . FirstOrDefault ( ) ;
183+ if ( string . IsNullOrEmpty ( address ) )
184+ return string . Empty ;
185+
186+ return address ;
187+ }
172188 }
173189
174190 public record FileServiceResult ( string Filename , string FileUrl , string FilePath ) ;
0 commit comments