mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 16:52:18 +00:00
fix problem when uploading assets from url
This commit is contained in:
parent
f7babb775e
commit
4389dce4d1
@ -145,7 +145,7 @@ describe('UploadAssetDialog', () => {
|
|||||||
fireEvent.change(screen.getByLabelText('URL'), { target: { value: urls } });
|
fireEvent.change(screen.getByLabelText('URL'), { target: { value: urls } });
|
||||||
fireEvent.click(screen.getByText('Next'));
|
fireEvent.click(screen.getByText('Next'));
|
||||||
|
|
||||||
await waitFor(() => expect(screen.getByText('Network Error')).toBeInTheDocument());
|
await waitFor(() => expect(screen.getByText('Failed to fetch')).toBeInTheDocument());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('snapshots the component with 4 URLs: 3 valid and one in failure', async () => {
|
it('snapshots the component with 4 URLs: 3 valid and one in failure', async () => {
|
||||||
|
|||||||
@ -14,5 +14,5 @@ export const server = setupServer(
|
|||||||
res(ctx.set('Content-Type', 'video/mp4'), ctx.body())
|
res(ctx.set('Content-Type', 'video/mp4'), ctx.body())
|
||||||
),
|
),
|
||||||
rest.get('*/not-working-like-cors.lutin', (req, res, ctx) => res(ctx.json({}))),
|
rest.get('*/not-working-like-cors.lutin', (req, res, ctx) => res(ctx.json({}))),
|
||||||
rest.get('*/some-where-not-existing.jpg', (req, res) => res.networkError())
|
rest.get('*/some-where-not-existing.jpg', (req, res) => res.networkError('Failed to fetch'))
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import { getFetchClient } from '@strapi/helper-plugin';
|
|
||||||
|
|
||||||
import { AssetSource } from '../constants';
|
import { AssetSource } from '../constants';
|
||||||
|
|
||||||
import { typeFromMime } from './typeFromMime';
|
import { typeFromMime } from './typeFromMime';
|
||||||
@ -9,20 +7,18 @@ function getFilenameFromURL(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const urlsToAssets = async (urls) => {
|
export const urlsToAssets = async (urls) => {
|
||||||
const { get } = getFetchClient();
|
|
||||||
const assetPromises = urls.map((url) =>
|
const assetPromises = urls.map((url) =>
|
||||||
get(url, {
|
fetch(url).then(async (res) => {
|
||||||
responseType: 'blob',
|
const blob = await res.blob();
|
||||||
timeout: 60000,
|
|
||||||
}).then((res) => {
|
const loadedFile = new File([blob], getFilenameFromURL(res.url), {
|
||||||
const loadedFile = new File([res.data], getFilenameFromURL(res.config.url), {
|
type: res.headers.get('content-type'),
|
||||||
type: res.headers['content-type'],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: loadedFile.name,
|
name: loadedFile.name,
|
||||||
url: res.config.url,
|
url: res.url,
|
||||||
mime: res.headers['content-type'],
|
mime: res.headers.get('content-type'),
|
||||||
rawFile: loadedFile,
|
rawFile: loadedFile,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user