0

Im using .net core 3.1 and i`m testing my APIs with swagger Ui.

i have one method that it steams video and i want to test it with swagger.

when i tried to load swagger page i got an error that swagger has failed to load

do you have any ideas how can i load stream video on swaggerUI?

        [Route("getFileById")]

    public FileResult getFileById()
    {

        return PhysicalFile($"H:/Movie/Joey/Joey.S01E01.FardaDL.mkv", "application/octet-stream", enableRangeProcessing: true);
    }

my swagger configuration

            app.UseSwagger();

        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
        });

and

            services.AddSwaggerGen();

enter image description here

Helen
  • 87,344
  • 17
  • 243
  • 314
mohammad kamali
  • 409
  • 4
  • 12
  • 1
    Post the actual error and post your Swagger configuration – Panagiotis Kanavos Jun 29 '20 at 09:54
  • @PanagiotisKanavos this post has been updated. thank you for your note – mohammad kamali Jun 30 '20 at 06:34
  • So the actual error is `Failed to load API definition`. There are several similar questions that point to misconfiguration [like this one](https://stackoverflow.com/questions/48450262/asp-net-core-swashbuckle-not-creating-swagger-json-file). Are you running the code under a virtual directory in IIS perhaps? In that case `/swagger` would actually point at a virtual directory named `swagger`, not the root of your own virtual directory – Panagiotis Kanavos Jun 30 '20 at 06:45
  • Check this [similar question too](https://stackoverflow.com/questions/56859604/swagger-not-loading-failed-to-load-api-definition-fetch-error-undefined). If you use `app.UseDeveloperExceptionPage` you may be able to get more info. In all cases though, the extension of the file path you use inside an action doesn't affect Swagger at all - it doesn't execute the action, it uses reflection over the methods and attributes. There's some other problem with the code - duplicate names? Missing attributes? Bad endpoint paths? – Panagiotis Kanavos Jun 30 '20 at 06:49

0 Answers0