mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 02:16:03 +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.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 () => {
|
||||
|
||||
@ -14,5 +14,5 @@ export const server = setupServer(
|
||||
res(ctx.set('Content-Type', 'video/mp4'), ctx.body())
|
||||
),
|
||||
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 { typeFromMime } from './typeFromMime';
|
||||
@ -9,20 +7,18 @@ function getFilenameFromURL(url) {
|
||||
}
|
||||
|
||||
export const urlsToAssets = async (urls) => {
|
||||
const { get } = getFetchClient();
|
||||
const assetPromises = urls.map((url) =>
|
||||
get(url, {
|
||||
responseType: 'blob',
|
||||
timeout: 60000,
|
||||
}).then((res) => {
|
||||
const loadedFile = new File([res.data], getFilenameFromURL(res.config.url), {
|
||||
type: res.headers['content-type'],
|
||||
fetch(url).then(async (res) => {
|
||||
const blob = await res.blob();
|
||||
|
||||
const loadedFile = new File([blob], getFilenameFromURL(res.url), {
|
||||
type: res.headers.get('content-type'),
|
||||
});
|
||||
|
||||
return {
|
||||
name: loadedFile.name,
|
||||
url: res.config.url,
|
||||
mime: res.headers['content-type'],
|
||||
url: res.url,
|
||||
mime: res.headers.get('content-type'),
|
||||
rawFile: loadedFile,
|
||||
};
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user