Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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.
Hi i've done something very similar in uSync.ContentEdition so the source might shed light on it
the create is simple enough
_mediaService = ApplicationContext.Current.Services.MediaService;
media = _mediaService.CreateMedia(name, parentId, mediaAlias);
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
FileStream s = new FileStream(file, FileMode.Open);
item.SetValue("umbracoFile", Path.GetFileName(file), s);
all of this assumes you haven't done something 'special' with the umbracoFile property.
hope that helps.
I am trying to upload a Image, but I get this error.
Make sure to call _mediaService.Save(media); after that.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted