Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS S3 image is not showing on edit #6437

Open
fvukojevic opened this issue Sep 4, 2024 · 0 comments
Open

AWS S3 image is not showing on edit #6437

fvukojevic opened this issue Sep 4, 2024 · 0 comments

Comments

@fvukojevic
Copy link

I have an entity that stores images in s3. This is how I modified my field:

            ImageField::new('mainImage', 'Slika Poduzeća')
                ->setBasePath($this->getBaseUrlForS3())
                ->setUploadDir('') // Dummy - unused we use s3
                ->setRequired(false)
                ->setHelp('Glavna slika poduzeća/logo (opcionalno)')
                ->setUploadedFileNamePattern('[randomhash].[extension]')  // Customize the pattern
                ->setFormTypeOption('upload_new', function (UploadedFile $file, string $uploadDir, string $fileName) {
                    $filePath = 'pages/' . $fileName;
                    $this->s3Service->uploadFile($file, $filePath);
                    return $filePath;
                })
                ->setFormTypeOption('upload_delete', function (string $filePath) {
                    // Delete the file from S3 via S3Service
                    $this->s3Service->deleteFile($filePath);
                })
                ->setFormTypeOption('mapped', true)
                ->setFormTypeOption('data_class', null) // Ensure that the field gets populated with the existing value

Saving works nicely, image is shown on both detail and list page, but when I click on edit, the image is not shown in the image field + if I just save then, it gets deleted like I removed it. Anyone able to tell me why and how to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant