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
I am trying to create a media item programatically, including uploading an image in Umbraco 6. I am using the new MediaService and calling mediaService.CreateMedia(mediaName, parentFolder, "Image"). That is all working fine, but what I don't know how to do is how to upload the file.
I have seen this post:
Which seems to get the media root directory and create the folders and files manually. This doesn't seem to work in Umbraco 6, as HttpContext.GetGlobalResourceObject("AppSettings", "MediaFilePath") is null.
How should I upload media files in Umbraco 6?
I suppose I was expecting there to be some methods exposed in the API for doing this sort of thing. For now, I have just used the code from the above post (http://our.umbraco.org/forum/developers/api-questions/3477-Creating-Media-Programatically) and just replaced HttpContext.GetGlobalResourceObject("AppSettings", "MediaFilePath") with a static reference to the media folder.
Did you ever get an answer to this? I'm facing the same issue.
No - I ended up just doing what I described above. Not really sure what the official way to do such a thing is - sorry I can't be much more help.
have you tried this? Mediaurl is a path here, so something like /myimages/test.jpg
var mediaService = ApplicationContext.Current.Services.MediaService;var media = mediaService.CreateMedia(property + "-" + id, 2111, "Image");media.SetValue("umbracoFile", mediaurl.Substring(mediaurl.LastIndexOf("/") + 1), new System.IO.FileStream(System.Web.Hosting.HostingEnvironment.MapPath(mediaurl), System.IO.FileMode.Open));
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted