HTML: How to download a pdf file using a link

Emanuele

I am trying to download a .pdf document from the external database Contentful using an HTML link on a user interface as shown below.

The problem I have is that everytime I click the link "PROJECT NOTES" I am redirected to an error page. Why my link does not download the pdf file?

map

Below the code I am using:

import Client from '../Contentful';


class Sidebar extends React.Component {
state = {
    ships: []
};

async componentDidMount() {
    let response = await Client.getEntries({
        content_type: 'cards'
    });
    const ships = response.items.map((item) => {
        const {
            name,
            slug,
            projectnotes
        } = item.fields;
        return {
            name,
            slug,
            projectnotes
        };
    });

    this.setState({
        ships
    });
}


getFilteredShips = () => {
    // operations .......
};

render() {
    return (
        <div className="map-sidebar">
            {this.props.activeShipTypes}
            <pre>
                {this.getFilteredShips().map((ship) => {
                    console.log(ship);

                    return (
                        <Card className="mb-2">
                            <CardImg />
                            <CardBody>
                                <CardTitle>
                                    <h3 className="thick">{ship.name}</h3>
                                </CardTitle>
                                <Row style={{ marginTop: '20px' }}>
                                    <div className="buttoncontainer">
                                        <div className="btn btn-cards">
                                            <a className="buttonLink" href={ship.projectnotes}>
                                                Project Notes
                                            </a>
                                        </div>
                                        <div className="btn btn-cards">
                                            <a className="buttonLink" href={ship.distancesandcontours}>
                                                Dist and Contours
                                            </a>
                                        </div>
                                    </div>
                                </Row>

                            </CardBody>
                        </Card>
                    );
                })}
            </pre>
        </div>
    );
}
}

export default Sidebar;

I can confirm that I am reading correctly the name of the field:

field

Maybe am I incorrectly assigning the path?

EDIT 2

I tried the following too but no download happened:

<a className="buttonLink" download={ship.projectnotes} href={ship.projectnotes}>Project Notes</a>

What I have done so far:

1) I was able to implement the link to the document but after I started using the external container Contentful, the pdf is not downloadable, contrarily to what I was hoping. Maybe there is an error in how I am assigning the path?

2) After researching more this problem I came across this post which was useful. It seems that in this post the problem could be the download?

I am a little bit confused. Thanks for pointing in the right direction.

Ian Devlin

You could try adding the download attribute to the a, it's quite well supported.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PDF file download using BlockingQueue

How To Download PDF file using Jersey?

Convert HTML to PDF and download the PDF file

Liferay 7.1 - How to add a link html for a pdf file

Vue/HTML/JS how to download a file to browser using the download tag

How to preview pdf file before download using jsPDF

How can I download a PDF file from an URL where the PDF is embedded into the HTML?

How to download a file from a link that is a forced download

How to download a file from a non static link using .bat script

How to download PDF file from web using python requests library

How to link a pdf download in JsonStore for Extjs 3.4

How do I download a file using SVN+ssh link?

Click a link to download file using curl

how to download a pdf file using php whose path is stored in the mysql?

How to download an excel File and PDF file using Jquery Ajax MVC

Auto download file from a link using javascript

How to download pdf file using asp.net?

How to download a pdf file instead of opening in the browserview using dotnetbrowser

PHP - download pdf file from link and save in local file folder

How to check if a link is a download link using Java?

How to download a vue file as pdf file in vuejs?

Save pdf file in google drive then get the url download link to specific column using google script

How to make HTML download link for .exe file?

How to download a pdf file using Flutter?

How to create a download link (PDF) in React

How do I insert a link to download a PDF file in Angular?

How to download a pdf file using beautiful soup if the link directly opens the pdf?

How to download shared file from Google Drive using a link?

How to download a file without available link but using selenium on click element