Coder Social home page Coder Social logo

Comments (6)

reinink avatar reinink commented on July 19, 2024 11

You need to make a normal, non-Inertia request to download files. All Inertia requests must return a valid Inertia response, which a file download of course isn't. So, instead of using an <inertia-link>, just use a regular <a>. ๐Ÿ‘

from inertia-laravel.

HoAnhTungPrimelabo avatar HoAnhTungPrimelabo commented on July 19, 2024 5

but can't post a form with an <A> tag
like <Link href="/download" method="post" as="button" type="button">download</Link>

from inertia-laravel.

boparaiamrit avatar boparaiamrit commented on July 19, 2024 4

You can use this in onClick

fetch(route('documents.download', { id: document.id }))
    .then((res) => res.blob())
    .then((blob) => {
      const file = window.URL.createObjectURL(blob)
      window.location.assign(file)
    })

from inertia-laravel.

rojtjo avatar rojtjo commented on July 19, 2024 1

You should be able to just use a regular form. Optionally with the target set to _blank to ensure a new window/tab opens and your Inertia app will just keep running.

<form action={yourDownloadUrl} method="post" target="_blank">
    <button>Download</button>
</form>

from inertia-laravel.

javdome avatar javdome commented on July 19, 2024 1

You can do it with a form... but remember the csrf token.

First, send the token to the Inertia view where you are going to insert the form:

return inertia ( 'YourView', [ 'token' => csrf_token() ] );

Now, in the view, insert the csrf token in a hidden input.
For instance, in a React view:

<form action = { route ('your.named.route', your.param) } method = "post">
    <input type="hidden" name="_token" value={props.token}/>
    <button>Download</button>
</form>

from inertia-laravel.

nwaweru avatar nwaweru commented on July 19, 2024

gular <a>.

Did you find a way around this?

I need to send a post request to download the file.

from inertia-laravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.