Mikael
Mikael

Reputation: 173

How to get file from drive - swagger

So I use swagger and have manage to get link loaded into the system correct. Now I need to get a file from the drive but it seems I cant get it right. Below is both the code for a link and one of my many tries to get a file from a drive.

This is the code

<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
     window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
  validatorUrl: null,
  docExpansion: 'none',
  operationsSorter: 'alpha',
   tagsSorter: 'alpha',
   urls: [{url: "C:/web/swagger/swaggerfiles//swagger.json", name: "Something"},
       {url: "http://worksjusstfine/swagger.json", name: "Something else"} ],

dom_id: '#swagger-ui',
deepLinking: true,
presets: [
  SwaggerUIBundle.presets.apis,
  SwaggerUIStandalonePreset
],
plugins: [
  SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
 })

 window.ui = ui
 }
</script>

Upvotes: 0

Views: 530

Answers (2)

programmer_girl
programmer_girl

Reputation: 71

Swagger expects the file url to be within the project, but the browser does not have access to your file system so you need to create an endpoint to access these files. The easiest solution is to create a JavaScript file to retrieve these files. You can write something like:

app.use('/swagger', express.static('path/to/file'));

Now your browser can access the directory using /swagger. In your urls array, simply use '/swagger/filename' instead of the entire path.

Upvotes: 1

Mikael
Mikael

Reputation: 173

To get this working I had to add a directory in IIS and then point out where the files were on the computer. Then I was able to get a http link.

Upvotes: 0

Related Questions