Milano
Milano

Reputation: 18745

Vuetify v-btn :href download opens XML in browser instead of downloading

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>

Upvotes: 1

Views: 623

Answers (2)

gear4
gear4

Reputation: 844

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.

Upvotes: 0

Vladimir Shefer
Vladimir Shefer

Reputation: 739

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?

Upvotes: 1

Related Questions