mirror of
https://github.com/strapi/strapi.git
synced 2025-08-15 04:08:04 +00:00
Merge pull request #5600 from strapi/features/media-lib-download-file
Add download file option
This commit is contained in:
commit
d06aa78f5f
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||||
/* eslint-disable react/jsx-fragments */
|
/* eslint-disable react/jsx-fragments */
|
||||||
import React, {
|
import React, {
|
||||||
Fragment,
|
Fragment,
|
||||||
@ -8,6 +9,7 @@ import React, {
|
|||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||||
|
import axios from 'axios';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Inputs } from '@buffetjs/custom';
|
import { Inputs } from '@buffetjs/custom';
|
||||||
@ -205,7 +207,22 @@ const EditForm = forwardRef(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClickDownload = () => {
|
const handleClickDownload = () => {
|
||||||
aRef.current.click();
|
axios
|
||||||
|
.get(prefixedFileURL, {
|
||||||
|
headers: new Headers({ Origin: window.location.origin, mode: 'cors' }),
|
||||||
|
responseType: 'blob',
|
||||||
|
})
|
||||||
|
.then(({ data }) => {
|
||||||
|
const blobUrl = URL.createObjectURL(data);
|
||||||
|
|
||||||
|
aRef.current.download = downloadFileName;
|
||||||
|
aRef.current.href = blobUrl;
|
||||||
|
|
||||||
|
aRef.current.click();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = e => {
|
const handleSubmit = e => {
|
||||||
@ -242,17 +259,14 @@ const EditForm = forwardRef(
|
|||||||
type="download"
|
type="download"
|
||||||
onClick={handleClickDownload}
|
onClick={handleClickDownload}
|
||||||
/>
|
/>
|
||||||
{isFileDownloadable && (
|
<a
|
||||||
<a
|
title={fileToEdit.fileInfo.name}
|
||||||
href={fileURL}
|
style={{ display: 'none' }}
|
||||||
title={fileToEdit.fileInfo.name}
|
ref={aRef}
|
||||||
download={downloadFileName}
|
>
|
||||||
style={{ display: 'none' }}
|
hidden
|
||||||
ref={aRef}
|
</a>
|
||||||
>
|
|
||||||
hidden
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
<CopyToClipboard onCopy={handleCopy} text={prefixedFileURL}>
|
<CopyToClipboard onCopy={handleCopy} text={prefixedFileURL}>
|
||||||
<CardControl color="#9EA7B8" type="link" />
|
<CardControl color="#9EA7B8" type="link" />
|
||||||
</CopyToClipboard>
|
</CopyToClipboard>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user