var imageFiles = Directory.GetFiles(_config.ProfileImageFileLocation);
foreach (var file in imageFiles)
{
var fileItem = new FileInfo(file);
Console.WriteLine($"uploading file {fileItem.Name}");
var media = _mediaService.CreateMedia(fileItem.Name, _config.ProfileImagesFolderId,
_config.MediaTypeAlias);
using (FileStream fileStream = fileItem.OpenRead())
{
media.SetValue(Constants.Conventions.Media.File, fileStream);
}
_mediaService.Save(media);
}
However I do not see the image itself, I am using blob storage so dont know if that has something todo with it or whether it does not like filestream being passed?
var fileItem = new FileInfo(file);
Console.WriteLine($"uploading file {fileItem.Name}");
using (var fileStream = fileItem.OpenRead())
{
IMedia media = _mediaService.CreateMedia(fileItem.Name, _config.ProfileImagesFolderId,
_config.MediaTypeAlias);
media.SetValue(_contentTypeBaseServiceProvider,Constants.Conventions.Media.File, fileItem.Name,fileStream);
_mediaService.Save(media);
}
This has got a bit further in that in media section the source of the image is correct its an actual url as opposed to what i had before "System.Io.Filestream" however the image still gives 404
Create image using media service outside web context
I am using https://github.com/callumbwhyte/sidecar and looking to create images using media service.
The bit I am stuck on is according to umbraco docs https://our.umbraco.com/Documentation/Reference/Management/Services/MediaService/Index/ when creating image you give it HttpPostedFileBase file however as i am not posting anything I am actually reading an image from a folder what do i pass in media.SetValue is it base64 encoded image string?
Regards
Ismail
Ok so got a bit further,
However I do not see the image itself, I am using blob storage so dont know if that has something todo with it or whether it does not like filestream being passed?
Hmm to image is set to System.Io.Filestream. So maybe base64 encoded is required?
Have a look at the imagefilter content app. That has the ability to save files so might help.
So after a little advice from Ronald on slack https://our.umbraco.com/Documentation/Reference/Management/Services/MediaService/Index/#creating-a-new-media-item-from-a-stream
I updated my code so it now looks like:
This has got a bit further in that in media section the source of the image is correct its an actual url as opposed to what i had before "System.Io.Filestream" however the image still gives 404
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.