Commit 3440fe10 by jaymehta

img upload

1 parent 014fb18d
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"@strapi/provider-email-nodemailer": "^4.3.8", "@strapi/provider-email-nodemailer": "^4.3.8",
"@strapi/provider-upload-aws-s3": "^4.3.9", "@strapi/provider-upload-aws-s3": "^4.3.9",
"@strapi/strapi": "4.3.6", "@strapi/strapi": "4.3.6",
"@strapi/utils": "^4.24.3",
"better-sqlite3": "7.4.6", "better-sqlite3": "7.4.6",
"csv-parse": "^5.5.5", "csv-parse": "^5.5.5",
"mysql": "^2.18.1", "mysql": "^2.18.1",
......
...@@ -56,6 +56,17 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -56,6 +56,17 @@ module.exports = createCoreController("api::experience.experience", () => ({
"Activity with the same name already exists, please rename the activity." "Activity with the same name already exists, please rename the activity."
); );
} }
let finalImageArray = [];
for (
let index = 0;
index < ctx.request.body.data.imagesComponent.length;
index++
) {
const element = ctx.request.body.data.imagesComponent[index];
finalImageArray = [...finalImageArray, { image: element }];
}
ctx.request.body.data.imagesComponent;
// Create Activity // Create Activity
const activity = await strapi.entityService.create( const activity = await strapi.entityService.create(
"api::experience.experience", "api::experience.experience",
...@@ -92,7 +103,7 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -92,7 +103,7 @@ module.exports = createCoreController("api::experience.experience", () => ({
contactPersonForBooking: contactPersonForBooking:
ctx.request.body.data.contactPersonForBooking, ctx.request.body.data.contactPersonForBooking,
approved: ctx.request.body.data.approved, approved: ctx.request.body.data.approved,
imagesComponent: ctx.request.body.data.imagesArrayComponent, imagesComponent: finalImageArray,
...ctx.request.body.data.daysBoolean, ...ctx.request.body.data.daysBoolean,
}, },
} }
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"info": { "info": {
"singularName": "test", "singularName": "test",
"pluralName": "tests", "pluralName": "tests",
"displayName": "test" "displayName": "test",
"description": ""
}, },
"options": { "options": {
"draftAndPublish": true "draftAndPublish": true
...@@ -15,14 +16,21 @@ ...@@ -15,14 +16,21 @@
"type": "string" "type": "string"
}, },
"images": { "images": {
"type": "media",
"multiple": true,
"required": false,
"allowedTypes": [ "allowedTypes": [
"images", "images",
"files", "files",
"videos", "videos",
"audios" "audios"
], ]
"type": "media", },
"multiple": true "imgComponent": {
"displayName": "imgComponent",
"type": "component",
"repeatable": true,
"component": "img-component.img-component"
} }
} }
} }
'use strict'; "use strict";
/** /**
* test controller * test controller
*/ */
const { createCoreController } = require('@strapi/strapi').factories; const { createCoreController } = require("@strapi/strapi").factories;
const { parseMultipartData, sanitizeEntity } = require("@strapi/utils");
module.exports = createCoreController('api::test.test'); module.exports = createCoreController("api::test.test", () => ({
async create(ctx) {
let entity;
if (ctx.request.is("multipart/form-data")) {
const { body: data, files } = ctx.request;
console.log("Data:", data);
console.log("Files:", files);
// Ensure imgComponent structure
if (data.imgComponent && Array.isArray(data.imgComponent)) {
data.imgComponent = data.imgComponent.map((item, index) => ({
...item,
image: files[`imgComponent[${index}].image`], // Ensure correct structure
}));
}
console.log("final", data.data, files);
try {
entity = await strapi.entityService.create("api::test.test", {
data,
files,
});
console.log("entity, ", entity);
return ctx.send({ payload: entity, success: true });
} catch (error) {
console.error(error);
ctx.throw(500, error.message);
}
} else {
ctx.throw(400, "Request must be multipart/form-data");
}
},
}));
...@@ -7,8 +7,15 @@ ...@@ -7,8 +7,15 @@
}, },
"options": {}, "options": {},
"attributes": { "attributes": {
"imageUrl": { "image": {
"type": "string" "allowedTypes": [
"images",
"files",
"videos",
"audios"
],
"type": "media",
"multiple": false
} }
} }
} }
{
"collectionName": "components_img_component_img_components",
"info": {
"displayName": "imgComponent"
},
"options": {},
"attributes": {
"image": {
"allowedTypes": [
"images",
"files",
"videos",
"audios"
],
"type": "media",
"multiple": false
}
}
}
This diff could not be displayed because it is too large.
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!