1

I'm having hard times making v-btn download XML file instead of opening it in the browser.

 <v-btn :disabled="!exportUrl" block x-large height="100" color="primary" :href="exportUrl" download>
      <v-icon left>
        mdi-download
      </v-icon>
      Stiahnuť
    </v-btn>

As far as I know it should download the file, not open the URL. What's wrong with that?

EDIT

The URL is http://127.0.0.1:8000/media/4e01d486-ee75-42bc-b695-8b365910ff3e.xml

EDIT 2

The rendered html looks like this:

<a data-v-51b210ff="" href="http://127.0.0.1:8000/media/10d4a7ad-399d-4003-8841-17eb98769ad9.xml" class="v-btn v-btn--block v-btn--is-elevated v-btn--has-bg theme--light v-size--x-large primary" style="height: 100px;" download=""><span class="v-btn__content"><i data-v-51b210ff="" aria-hidden="true" class="v-icon notranslate v-icon--left mdi mdi-download theme--light"></i> Stiahnuť </span></a>
Milano
  • 18,048
  • 37
  • 153
  • 353

2 Answers2

1

It depends on the Content-Type header which is set in the file response.

If it is application/xml, the file will be opened as text. If it is abcent or application/octet-stream, then download action will be triggered.

See this question What content type to force download of text response?

Vladimir Shefer
  • 661
  • 3
  • 19
  • That's not the case. I don't want to rely on the server. I have the URL and I want to make a button that downloads it instead of rendering it in the browser. – Milano May 08 '21 at 23:08
  • @Milano, you have asked why is this happening and i answered. – Vladimir Shefer May 08 '21 at 23:10
  • Ok thanks. Do you know if it's possible to make it download the file instead of rendering it? I thought that the "download" parameter would work. – Milano May 08 '21 at 23:16
0

In HTML 5, there is a download attribute on the a tag. You just need to place the downloaded file's name in the attribute, and it should automatically download the file for you.

gear4
  • 745
  • 6
  • 13