I have a custom module which supports uploading an image, with the intention of importing the image into the Media Library, and also adding the image as a MediaPart to the MediaParts collection of a MediaLibraryPicker field on a content item.
In the code snippet below, "file" is the uploaded file of type HttpPostedFileBase.
var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, file.FileName);
The file is correctly saved to the file system in the specified location.
However, the file never appears in the Media Library. Why not?
Also, the resulting MediaPart looks great, but when I add it to the MediaParts collection of my content item's MediaLibraryPicker field, it isn't persisted. Perhaps because the content item isn't evidently changed merely by adding an item to the MediaParts
collection; but what is the solution? I do not want to publish the content item; it needs to remain in a draft state at this point.
Any clues would be most appreciated.