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

[BUG] Importing Images while using AWS S3 strips extention and folder #26

Closed
kenshobotuser opened this issue Jul 28, 2022 · 19 comments
Closed
Assignees

Comments

@kenshobotuser
Copy link

Describe the bug
I am uploading an entry into a collection which has an image. The image uploads but I then get a white screen on the collection page. Looking at the database, I can see the URL got imported, but the aws folder and the image extension both seemed to have been stripped out. If I upload the image using the media upload button it works properly.

Screenshot 2022-07-28 at 20 06 23

In the screenshot above, the first entry was uploaded normally, but the second and third were imported and they are missing both the image extension and the image folder. The second image should be https://giochigatsby.s3.eu-west-1.amazonaws.com/misc_images/chrismitoli_2021-10-26-170225_icpo.jpeg instead of https://giochigatsby.s3.eu-west-1.amazonaws.com/chrismitoli_2021-10-26-170225_icpoundefined.

This is the import JSON I am currently using

[
            {
                "id": "23",
                "username": "christopher",
                "firstName": "Christopher",
                "lastName": "Mitoli",
                "photo": "https://giochigatsby.s3.eu-west-1.amazonaws.com/misc_images/chrismitoli_2021-10-26-170225_icpo.jpeg",
                "metaTitle": "Christopher",
                "metaDescription": null
            }
]

Additional context
I am using the AWS-S3 provider plugin

@kenshobotuser
Copy link
Author

just realised I was still signed into the wrong account :(.

@Baboo7
Copy link
Owner

Baboo7 commented Jul 28, 2022

If there is no issue I close this one ;)

@Baboo7 Baboo7 closed this as completed Jul 28, 2022
@kenshobotuser
Copy link
Author

Hi, there is still a issue with this unfortunately :(.

@Baboo7
Copy link
Owner

Baboo7 commented Jul 29, 2022

What the issue?

@kenshobotuser
Copy link
Author

So, using the JSON below, I am trying to import a image into a media field using a URL

[
            {
                "id": "23",
                "username": "christopher",
                "firstName": "Christopher",
                "lastName": "Mitoli",
                "photo": "https://giochigatsby.s3.eu-west-1.amazonaws.com/misc_images/chrismitoli_2021-10-26-170225_icpo.jpeg",
                "metaTitle": "Christopher",
                "metaDescription": null
            }
]

Right after the import I get a white screen and when I check the files table in the database, the URL for the image was imported but with the image folder missing and the image extension shown as undefined. So this is what end up being saved in the db

https://giochigatsby.s3.eu-west-1.amazonaws.com/chrismitoli_2021-10-26-170225_icpoundefined

Which is what is causing the white screen. If I add the correct image extension and folder to the URL, everything works as expected. Also, if I upload the image to the media field directly, it uses the correct URL.

I am using the AWS S3 provider plugin for saving images to S3, I do not know if that might have any bearing on the issue

@Baboo7
Copy link
Owner

Baboo7 commented Jul 29, 2022

just realised I was still signed into the wrong account :(.

To better understand, what did you mean?

@kenshobotuser
Copy link
Author

Ah, the github account i wrote the issue with is a bot account not my personal account. I forgot to log out of it after setting up some pipelines.

@kenshobotuser
Copy link
Author

So I noticed the issue is still closed, does that mean it doesn't come from the plugin?

@Baboo7 Baboo7 reopened this Jul 31, 2022
@Baboo7
Copy link
Owner

Baboo7 commented Jul 31, 2022

I will try to reproduce the issue using your image url

@keegankb93
Copy link

keegankb93 commented Aug 2, 2022

I can confirm that this happens when using AWS. Can't confirm with other providers.

Context for reproduction is that we are using two strapi instances, one for staging and one for production and we transfer between the two, so I'm not sure if the author of this thread is doing something similar.

@kenshobotuser
Copy link
Author

Whew, I'm glad it wasn't me mucking things up :). My circumstance is that I am migrating my content from a different CMS to Strapi. So I have all the content exported in JSON format and I just needed to import them into Strapi. Your plugin is working perfectly for that barring the image issue.

@ohayak
Copy link

ohayak commented Aug 3, 2022

I confirm the same behavior with AWS s3
When I try to import somethis like:

"id": 1,
		"shortName": "Home",
		"slug": "",
		"createdAt": "2022-08-03T08:33:39.856Z",
		"updatedAt": "2022-08-03T08:33:39.856Z",
		"publishedAt": "2021-10-22T08:11:55.490Z",
		"locale": "en",
		"metadata": {
			"id": 2,
			"metaTitle": "Strapi corporate site starter",
			"metaDescription": "Build a fully editable site with Strapi",
			"twitterCardType": "summary",
			"twitterUsername": null,
			"shareImage": {
				"id": 3,
				"name": "undraw-content-team",
				"alternativeText": "undraw-content-team",
				"caption": "undraw-content-team",
				"width": 1119,
				"height": 712,
				"formats": {
					"thumbnail": {
						"name": "thumbnail_undraw-content-team",
						"hash": "thumbnail_undraw_content_team_9bca9b3438",
						"ext": ".png",
						"mime": "image/png",
						"path": null,
						"width": 245,
						"height": 156,
						"size": 13.68,
						"url": "https://bkt.s3.eu-west-1.amazonaws.com/thumbnail_undraw_content_team_9bca9b3438.png"
					},
					"large": {
						"name": "large_undraw-content-team",
						"hash": "large_undraw_content_team_9bca9b3438",
						"ext": ".png",
						"mime": "image/png",
						"path": null,
						"width": 1000,
						"height": 636,
						"size": 71.49,
						"url": "https://bkt.s3.eu-west-1.amazonaws.com/large_undraw_content_team_9bca9b3438.png"
					},
					"medium": {
						"name": "medium_undraw-content-team",
						"hash": "medium_undraw_content_team_9bca9b3438",
						"ext": ".png",
						"mime": "image/png",
						"path": null,
						"width": 750,
						"height": 477,
						"size": 49.93,
						"url": "https://bkt.s3.eu-west-1.amazonaws.com/medium_undraw_content_team_9bca9b3438.png"
					},
					"small": {
						"name": "small_undraw-content-team",
						"hash": "small_undraw_content_team_9bca9b3438",
						"ext": ".png",
						"mime": "image/png",
						"path": null,
						"width": 500,
						"height": 318,
						"size": 31.36,
						"url": "https://bkt.s3.eu-west-1.amazonaws.com/small_undraw_content_team_9bca9b3438.png"
					}
				},
				"hash": "undraw_content_team_9bca9b3438",
				"ext": ".png",
				"mime": "image/png",
				"size": 15.13,
				"url": "https://bkt.s3.eu-west-1.amazonaws.com/undraw_content_team_9bca9b3438.png",
				"previewUrl": null,
				"provider": "aws-s3",
				"provider_metadata": null,
				
				"createdAt": "2022-08-03T08:33:37.911Z",
				"updatedAt": "2022-08-03T08:33:37.911Z"
			}

This is what's I end up with int the db

Screenshot 2022-08-03 at 20 20 52

And in my S3 new files created:
Screenshot 2022-08-03 at 20 53 00

@Alex01d
Copy link
Contributor

Alex01d commented Aug 4, 2022

And that makes strapi pages with those images die.
Also the plugin creates database records of images even if their URLs return 404.

So we definitely need extra checks.

@Baboo7
Copy link
Owner

Baboo7 commented Aug 4, 2022

Seeing the impact of the issue this will be my priority

@kenshobotuser
Copy link
Author

Many thanks 🙏

@Baboo7
Copy link
Owner

Baboo7 commented Aug 7, 2022

Version 1.9.2 is available. Media import has been reworked for a more robust and consistent behavior:

  • media import to AWS and other provider should work as expected
  • import fails if the provided media url returns a status code ≠ 2xx
  • media import fully relies on strapi implementation now
  • expected data structure for media has been updated in the doc (no breaking changes introduced)

@kenshobotuser
Copy link
Author

Works like a charm. Many thanks for the quick fix 🙏

@ohayak
Copy link

ohayak commented Aug 8, 2022

version 1.9.2 is working as expected, but in 1.10 files are not uploaded to db nor the bucket

@Baboo7
Copy link
Owner

Baboo7 commented Aug 8, 2022

Give a try to version 1.10.1, a fix has been pushed thanks to @Alex01d

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

5 participants