Open strapi123 opened 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, },
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:
Expected behavior Images must be uploaded as IMAGE type in media library so that we can see its preview.
Screenshots
Additional context Using Strapi 4.24.5 V