mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
Add cancel fetch file
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
2f6cec21e3
commit
43ab0edeb8
@ -78,10 +78,13 @@ const ModalStepper = ({
|
||||
try {
|
||||
await Promise.all(
|
||||
files.map(file => {
|
||||
const { source } = file;
|
||||
|
||||
return axios
|
||||
.get(file.fileURL, {
|
||||
headers: new Headers({ Origin: window.location.origin, mode: 'cors' }),
|
||||
responseType: 'blob',
|
||||
cancelToken: source.token,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
const createdFile = new File([data], file.fileURL, {
|
||||
@ -123,9 +126,14 @@ const ModalStepper = ({
|
||||
|
||||
const handleCancelFileToUpload = fileOriginalIndex => {
|
||||
const fileToCancel = filesToUpload.find(file => file.originalIndex === fileOriginalIndex);
|
||||
const { source } = fileToCancel;
|
||||
|
||||
// Cancel upload
|
||||
fileToCancel.abortController.abort();
|
||||
if (source) {
|
||||
source.cancel('Operation canceled by the user.');
|
||||
} else {
|
||||
// Cancel upload
|
||||
fileToCancel.abortController.abort();
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: 'REMOVE_FILE_TO_UPLOAD',
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// import axios from 'axios';
|
||||
import axios from 'axios';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
const getTempsIds = alreadyUploadedFiles => {
|
||||
@ -18,11 +18,15 @@ const createNewFilesToDownloadArray = (filesURLArray, alreadyUploadedFiles) => {
|
||||
return acc;
|
||||
}
|
||||
|
||||
const CancelToken = axios.CancelToken;
|
||||
|
||||
// TODO change with axios cancel request
|
||||
const abortController = new AbortController();
|
||||
const source = CancelToken.source();
|
||||
|
||||
acc.push({
|
||||
abortController,
|
||||
source,
|
||||
file: null,
|
||||
fileInfo: {
|
||||
alternativeText: '',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user