Images uploaded with the API show draft status on publish
Do I have the code wrong?
See attached...they have both the green publishes state, but the text of draft. If I open one, then click Publish, the text then properly changes to Published though.
So an I missing something?
public void UploadImage(System.IO.Stream stream, string name, string extension, string fullname)
try
this.LibraryManager.Provider.SuppressSecurityChecks = true;
Telerik.Sitefinity.Libraries.Model.Image newImage = LibraryManager.CreateImage();
//Set its album
newImage.Parent = this.LibraryManager.GetAlbums().FirstOrDefault(x => x.Title ==
"Content"
);
var imageName = name;
newImage.Title = imageName;
newImage.UrlName = Util.GetUrl(imageName);
LibraryManager.Upload(newImage, stream, extension);
LibraryManager.RecompileItemUrls<Telerik.Sitefinity.Libraries.Model.Image>(newImage);
LibraryManager.Publish(newImage);
LibraryManager.SaveChanges();
catch(Exception ex)
errorsLiteral.Text = fullname +
"<br />"
;
Hi Steve,
I have taken a look at your code and the problem most likely comes from the fact that the you have not informed the workflow about the changes. Can you try to run your code with the modifications that I have made to it:
public
void
UploadImage(System.IO.Stream stream, Guid masterImageId,
string
name,
string
extension,
string
fullname)
try
this
.LibraryManager.Provider.SuppressSecurityChecks =
true
;
Telerik.Sitefinity.Libraries.Model.Image newImage = LibraryManager.CreateImage(masterImageId);
//Set its album
newImage.Parent =
this
.LibraryManager.GetAlbums().FirstOrDefault(x => x.Title ==
"Content"
);
var imageName = name;
newImage.Title = imageName;
newImage.UrlName = Util.GetUrl(imageName);
LibraryManager.Upload(newImage, stream, extension);
LibraryManager.RecompileItemUrls<Telerik.Sitefinity.Libraries.Model.Image>(newImage);
LibraryManager.Publish(newImage);
LibraryManager.SaveChanges();
var bag =
new
Dictionary<
string
,
string
>();
bag.Add(
"ContentType"
,
typeof
(Image).FullName);
WorkflowManager.MessageWorkflow(masterImageId,
typeof
(Image),
null
,
"Publish"
,
false
, bag);
catch
(Exception ex)
errorsLiteral.Text = fullname +
"<br />"
;
public
void
UploadImageFluent()
var request = System.Net.WebRequest.Create(
"http://localhost:9999/images/test/dog.jpg"
)
as
System.Net.HttpWebRequest;
var response = request.GetResponse()
as
System.Net.HttpWebResponse;
using
(MemoryStream stream =
new
MemoryStream())
using
(var source = response.GetResponseStream())
source.CopyTo(stream);
var fluent = App.WorkWith();
var userUploadAlbum = fluent.Albums().Where(a => a.UrlName ==
"default-album"
).Get().SingleOrDefault();
var newImage = fluent.Image().CreateNew().Do(
image =>
image.Description =
"Image Description"
;
image.Author =
"Image Author"
;
image.Parent = userUploadAlbum;
image.Title =
"Image Title"
;
image.UrlName =
"image-title"
;
image.Extension =
".jpg"
;
)
.CheckOut()
.UploadContent(stream,
".jpg"
)
.CheckIn()
.Do(image => image.ApprovalWorkflowState =
"Published"
; )
.Publish()
.SaveChanges();
Ah thanks Victor, that must be it
seems weird indeed...
So what's gonna happen with Dropbox in v5.2 ? Anything added gets 'draft' statement and as soon as a Dropbox hickup occurs and something gets resynced it'll get unpublished?
Jochem.
Hey Victor,
Okay so I modified it like this
public
void
UploadImage(System.IO.Stream stream,
string
name,
string
extension,
string
fullname,
string
libraryName)
try
Guid imageID = Guid.NewGuid();
this
.LibraryManager.Provider.SuppressSecurityChecks =
true
;
Telerik.Sitefinity.Libraries.Model.Image newImage = LibraryManager.CreateImage(imageID);
//Set its album
var album =
this
.LibraryManager.GetAlbums().FirstOrDefault(x => x.Title == libraryName);
if
(album.Images().Count(x => x.Title == name) == 0)
newImage.Description =
""
;
newImage.Author =
"sleuthagain"
;
newImage.Parent = album;
newImage.Title = name;
newImage.UrlName = Util.GetUrl(name);
newImage.Extension = extension;
LibraryManager.Upload(newImage, stream, extension);
LibraryManager.RecompileItemUrls<Telerik.Sitefinity.Libraries.Model.Image>(newImage);
LibraryManager.Lifecycle.Publish(newImage);
LibraryManager.SaveChanges();
var bag =
new
Dictionary<
string
,
string
>();
bag.Add(
"ContentType"
,
typeof
(Image).FullName);
WorkflowManager.MessageWorkflow(imageID,
typeof
(Image),
null
,
"Publish"
,
false
, bag);
_count++;
catch
(Exception ex)
errorsLiteral.Text = fullname +
"<br />"
;
@Victor missing this?
Ok victor, that fluent code worked, going in published now :)
...however I still can't link those images to a module builder item in code...using the sample code.
screencast.com/.../hxrCnrVuNT
var image =
this
.MyLibraryManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible ==
true
&& i.Title.ToString().ToLower() == imageToFind);
if
(image !=
null
)
dictionaryEntryItem.AddImage(
"MainImage"
, image.Id);