Can anyone help me with some code to create images programmatically in V7 API? I have got the Node stuff sorted using Umbraco.Core.Serivices.ContentService, but the media stuff is not being so nice.
Esentially, I have created a user control to which people can create nodes, then upload images to associate with the node. I want to add these images to the Media section.
Create Media Programmatically in V7
Can anyone help me with some code to create images programmatically in V7 API? I have got the Node stuff sorted using Umbraco.Core.Serivices.ContentService, but the media stuff is not being so nice.
Esentially, I have created a user control to which people can create nodes, then upload images to associate with the node. I want to add these images to the Media section.
Thanks in advance.
Hugh
Hi i've done something very similar in uSync.ContentEdition so the source might shed light on it
https://github.com/KevinJump/jumoo.usync/blob/master/jumoo.usync.content/MediaImporter.cs#L85
and
https://github.com/KevinJump/jumoo.usync/blob/master/jumoo.usync.content/helpers/FileHelper.cs#L236
the create is simple enough
the import media file (in FileHelper above) was more tricky.
you need to call IMediaItem.SetValue and pass the filename and stream to upload the umbracoFile
all of this assumes you haven't done something 'special' with the umbracoFile property.
hope that helps.
Hi Kevin, I am trying to upload a Image, but I get this error.
Make sure to call
_mediaService.Save(media);
after that.Hi Hugh,
Please have a look on these threads explaining very detail about how?
https://stackoverflow.com/questions/24633151/umbraco-media-services-create-media
https://techiespice.com/2018/11/01/create-folders-upload-images-under-media-in-umbraco/amp/
Regards Dhanesh :)
is working on a reply...