How to upload editor js images using symfony framework?
Here is my upload function in Controller. Codes in the function works as I have tried to upload by using traditional forms. <form></form>
/**
* @Route("/uploadImage", name="upload")
*/
public function upload(Request $request): Response
{
$file = $request->files->get['image'];
$uploads_dir = $this->getParameter('uploads_dir');
$filename = md5(uniqid()) . ' . ' . $file->guessExtension();
$file->move(
$uploads_dir,
$filename
);
$fileurl = $uploads_dir + $filename;
$response = JsonResponse::fromJsonString('{"success":1, "file": {"url":"$fileurl"}}');
return $response;
}
services.yaml (set up for storing images)
parameters:
uploads_dir: '%kernel.project_dir%/public/uploads'
And this is my code in Javascript for Editorjs:
const editor = new EditorJS({
holder: 'editor',
tools: {
header: Header,
list: List,
checklist: Checklist,
quote: Quote,
code: CodeTool,
table: Table,
image: {
class: ImageTool,
config: {
endpoints: {
byFile: '/uploadImage', // Your backend file uploader endpoint
byUrl: '/uploadImage', // Your endpoint that provides uploading by Url
}
}
}
}
});
I have tried to pass image data to the controller to process uploading, but it fails.