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

Created image through media service - it's not working #10

Open
simoazzo opened this issue Mar 3, 2021 · 0 comments
Open

Created image through media service - it's not working #10

simoazzo opened this issue Mar 3, 2021 · 0 comments

Comments

@simoazzo
Copy link

simoazzo commented Mar 3, 2021

I am trying to create an image programmatically, but the image being uploaded on AWS S3 bucket is becoming as 0KB, so no image is being uploaded.

Any clue?

This is the code:

if (imageBytes != null & imageBytes.Any())
                    {
                        var imageAsIMedia = mediaService.CreateMedia(item.title, new Guid(Constants.Constants.CommunityItemsFolderGuId), global::Umbraco.Core.Constants.Conventions.MediaTypes.Image);

                        using (Stream stream = new MemoryStream(imageBytes))
                        {
                            var imageFromStream = Image.FromStream(stream);
                            var imageFormat = ImageHelpers.GetImageFormat(imageFromStream);

                            imageAsIMedia.SetValue(Services.ContentTypeBaseServices, "umbracoFile", item.title + imageFormat, stream);

                            var imageSaveResult = mediaService.Save(imageAsIMedia);
                            if (imageSaveResult.Success)
                            {
                                request.SetValue(Constants.Constants.CommunityItemPhotoAlias, imageAsIMedia.GetUdi());

                                var mediaAsIPublishedContent = Umbraco.Media(imageAsIMedia.Id);

                                imageUrl = mediaAsIPublishedContent.Url(null, UrlMode.Absolute);
                            }
                        }
                    }
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