Welcome Guest Search | Active Topics | Members | Log In | Register
Programatically add objects + sync Albums Options
nr2ae
Posted: Saturday, October 25, 2008 9:06:15 PM
Rank: Newbie

Joined: 10/20/2008
Posts: 2
I've been trying to integrate GSP with FCKEditor File Browser + Quick Upload.

1. How can I add/upload a file to /mediaobjects and tell the GSP to recognize that file? Is there a method for adding / synchronizing that I can use? I already tried reading the API, but I really have no idea where to start. I have the album path ("/mediaobjects/SomeAlbum") and the new file name.

2. Is there a better way to reference the files in the GSP from FCKEditor. I've been using "/mediaobjects/SomeAlbum/zOpt_someFile.jpeg" but I know it can break if the album name has been changed, or the object has been moved.

Is there a function for returning the list of objects urls within an album that use "/handler/getmediaobject.ashx" that resist those changes?

Thanks you very much.

PS. You might want to check line 93 of albumedittemplate.ascx. The label was "UC_Album_Header_Album_Title_Header_Text" but it should be "UC_Album_Header_Edit_Album_Title_Header_Text", right? I use different values for those 2 fields so I notice it.
Roger Martin
Posted: Sunday, October 26, 2008 5:35:10 PM
Rank: Administration

Joined: 8/3/2007
Posts: 844
Location: Fort Atkinson, WI
The best way to learn the API is to see how the web front end accomplishes tasks. So, to see how to add a file to the media gallery, take a look at how the Add Objects page does it (~/task/addobjects.aspx). Since my boy is napping and I have a few minutes, I'll write up a 2-minute tutorial.

The web project gsweb interacts with the business layer to get just about everything done. Within the business layer, you will often start with the Factory class to instantiate objects. To get a reference to the top level album, use this:

Code:
IAlbum rootAlbum = Factory.LoadRootAlbumInstance();


To iterate through the child objects of the root album:

Code:
foreach (IGalleryObject galleryObject in rootAlbum.GetChildGalleryObjects())
{
  string title = galleryObject.Title;
  IDisplayObject thumbnail = galleryObject.Thumbnail;
  IDisplayObject compressedImage = galleryObject.Optimized;
  IDisplayObject originalFile = galleryObject.Original;
}


The child gallery object may be an album, image, video, audio, generic media object, or external media object. Each of these map to a different class that inherits from the GalleryObject class.

The GetChildGalleryObjects method has overloads to help you return them sorted, or maybe you only want albums, or maybe you only want the photos.

To add an image to the root album:

Code:
IAlbum rootAlbum = Factory.LoadRootAlbumInstance();
string pathToImage = @"C:\mypic.jpg";
IGalleryObject galleryObject = Factory.CreateMediaObjectInstance(pathToImage, rootAlbum);
galleryObject.CreatedByUserName = HttpContext.Current.User.Identity.Name;
galleryObject.DateAdded = DateTime.Now;
galleryObject.Save();


To generate an URL to an object take a look at the GetMediaObjectUrl method in the GspPage class at ~/gsweb/CodeFiles/. This class is the base class for all pages, so the method is available to every page. For example:

Code:
string thumbnailUrl = GetMediaObjectUrl(galleryObject, DisplayObjectType.Thumbnail);


This gives you an url that uses the ASHX handler you can assign to an <img> tag. It'll look something like this: /dev/gs/handler/getmediaobject.ashx?moid=34&amp;aid=8&amp;mo=C%3A%5Cgs%5Cmypics%5Cbirthday.jpeg&amp;mtc=1&amp;dt=1&amp;isp=false

If you have encryptMediaObjectUrlOnClient="true" in galleryserverpro.config (which is the default), the query string parameter will be encrypted so that end users won't be able to discover the path to your files.

Thanks for the bug report about the resource. It is now fixed.

Oops, I have a poopy diaper to change. Gotta run!



Roger Martin
Lead Developer for Gallery Server Pro
nr2ae
Posted: Saturday, November 08, 2008 7:42:44 PM
Rank: Newbie

Joined: 10/20/2008
Posts: 2
Thank you very much for the tips. :-D
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.2 (NET v2.0) - 9/27/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.