var mediaService = ApplicationContext.Current.Services.MediaService;
//CreateMedia takes the name of the media you are created, the id of the parent and finally the alias of the MediaType that you want the media to be based on.
var media = mediaService.CreateMedia("myMediaFile", -1, "Image");
mediaService.Save(media);
And if you want to upload an image that is posted as a HttpPostedFile you simply add it to the umbracoFile property:
media.SetValue("umbracoFile", thePostedFile);
//And then save it similar to the above snippet
mediaService.Save(media);
Creating a media object with the v6.0 API? HELP!!
I am trying to create a new media object with the V6 API. Has anyone got any ideas using Umbraco.Core,Models namespace?
Thanks. Charlie :)
Hi Charles,
In v6 you would do something like this:
And if you want to upload an image that is posted as a HttpPostedFile you simply add it to the umbracoFile property:
Hope this helps.
- Morten
Thanks so much i will give that a try :)
Hi, when i say creating a media object i may have got my self slightly wrong :).. sorry.
In V4.10 i was able to create a media object by doing:
new Media(ID);
So do i now have to instance a service, create my media in order to create a media object?
Thanks for your help :)
Okay, so you want to get an existing media object and not create a new one.
You still use the MediaService, but use the GetById method:
- Morten
is working on a reply...