title: How to download files using Swag golang library?
body: <p>I am trying to make a <strong>REST API</strong> using <strong>gin-gonic</strong> in <strong>golang</strong>, which takes some path parameters from a <strong>GET</strong> request &amp; <strong>downloads</strong> that file.</p>
  <p>That works correctly by <strong>curl</strong> command.
  However, when I add <strong>swagger UI</strong> documentation, then if the downloaded file is text or image, it is just displayed in that webpage, but I can't see any download option. Further the browser hangs if I enter the path of a video file.</p>
  <p>Also, the <strong>MIME</strong> type of the file to be downloaded is determined correctly from <strong>gin-gonic</strong>. But, to download the file via <strong>swagger UI interface</strong>, I am using hardcoded <strong>@Accept</strong> &amp; <strong>@Produce</strong> swagger UI comment annotations. It should ideally determine that MIME type automatically.</p>
  <p>Currently the response type is listed as drop down, where I get various options.
  I need that to automatically detect correct MIME type &amp; display a <strong>download</strong> button if possible</p>
  <p>My code for the GET request is:</p>
  <pre><code>// DownloadObject godoc
  // @Summary Download object
  // @Description Download object
  // @Produce application/json
  // @Produce text/plain
  // @Produce application/octet-stream
  // @Produce video/mp4
  // @Produce image/png
  // @Produce image/jpeg
  // @Produce image/gif
  // @Param rootPath path string true &quot;Root Path&quot;
  // @Param filePath path string true &quot;File Path&quot;
  // @Header 200 {string} Token &quot;qwerty&quot;
  // @Router /transfer/{rootPath}/{filePath} [get]
  func DownloadObject(c *gin.Context) {
  
      // Get rootPath &amp; filePath from GET request
      rootPath := c.Param(&quot;rootPath&quot;)
      filePath := c.Param(&quot;filePath&quot;)
  
  
      // Some code to get an io.Reader object &quot;download&quot;
  
      _, err = io.Copy(c.Writer, download)
      if err != nil {
          c.Status(http.StatusInternalServerError)
          log.Print(err)
          return
      }
  
      err = download.Close()
      if err != nil {
          c.Status(http.StatusInternalServerError)
          log.Print(err)
          return
      }
      
      c.Writer.Header().Add(&quot;Content-Disposition&quot;, fmt.Sprintf(&quot;attachment; filename=%&quot;, filePath))
      c.Writer.Header().Add(&quot;Content-Type&quot;, c.GetHeader(&quot;Content-Type&quot;))
      // Object download completed &amp; closed successfully
  
  }
  </code></pre>
  <p>Am I missing something here?</p>