Baboo7 / strapi-plugin-import-export-entries

Import/Export data from and to your database in just few clicks.
175 stars 86 forks source link

[BUG] JPG/PNG images uploaded as DOC in Media Library #199

Open strapi123 opened 2 weeks ago

strapi123 commented 2 weeks ago

Describe the bug I am trying import the data from one server to another, the collection data is importing properly but the images jpg and png images are getting uploaded as DOC in media library with no-preview. SVG images are uploaded properly with the preview the issue is only with png and jpg.

We are storing assets in AWS s3. I have exported the data using Json V2 option.

Can some help with this issue.

To Reproduce Steps to reproduce the behavior:

  1. Go to anyone collection and click import data type
  2. Click on import
  3. Data imported successfully.
  4. Images are uploaded as DOC type in media library.

Expected behavior Images must be uploaded as IMAGE type in media library so that we can see its preview.

Screenshots

Screenshot 2024-08-27 at 5 26 10 PM Screenshot 2024-08-27 at 5 26 31 PM

Additional context Using Strapi 4.24.5 V

strapi123 commented 2 weeks ago

Found the issue @Baboo7. In the fetchFile function the content type is not coming from headers.response which sets it to null for PNG and JPG images.

const fetchFile = (url) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; try { const response = yield (0, node_fetch_1.default)(url); const contentType = ((_b = (_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')) === null || _b === void 0 ? void 0 : _b[0]) || ''; console.log("contentType ", contentType, " response ", response.headers) const contentLength = parseInt(response.headers.get('content-length') || '0', 10) || 0; const buffer = yield response.buffer(); const fileData = getFileDataFromRawUrl(url); const filePath = yield writeFile(fileData.name, buffer); return { name: fileData.name, type: contentType, size: contentLength, path: filePath, }; } catch (error) { throw new Error(Tried to fetch file from url ${url} but failed with error: ${error.message}); } });

So in importFile I add mime as the parameter as it gets added from exportData and updated files object with type: mime instead of getting from response.headers.

files: { name: file.name, type: mime, size: file.size, path: file.path, },