Import images through the API

We are trying out importing images through the API, but haven't had any luck. Has anyone already tried this? Is there an import function or any function specific to images?

string myEdt1 = "EDTXML";
string guidid = "GUID-"+Guid.NewGuid().ToString();
string version = "1";
string xmlMetadata = "<ishfields>" +
"<ishfield name='FTITLE' level='logical'>New Image</ishfield>" +
"<ishfield name='DOC-LANGUAGE' level='lng'>en-US</ishfield>" +
"<ishfield name='FSTATUS' level='lng'>Draft</ishfield>" +
"</ishfields>";
string someUrl = "">www.google.com/.../ps_logo2.png";

using (var webClient = new WebClient())
{
byte[] imageBytes = webClient.DownloadData(someUrl);
//Create image
userClientDocumentObj.Create(2521468, "ISHIllustration", ref guidid, ref version, "en-US", "Low",
xmlMetadata, myEdt1, imageBytes);
}

  • Hi Akheil,

    I can tell you that the Client Tools of the product (so Publication Manager, Content Importer, AuthoringBridge,...) and ISHRemote are using the _same_ public API as you are. So pretty sure it is possible :-)

    I have no idea what "WebClient" refers to in your sample code, is this ASMX/SOAP or WCF/SOAP? Are you authenticated? Can I assume that your user has write permission in that 2521468 folder?

    What is the error you receive?

    I also notice that you state myEdt1 = "EDTXML" ... so you are forcing your downloaded Google image to pass the XML IWrite plugins you have confgured. Probably "EDTPNG" makes more sense (full list available via ISHRemote Find-IshEDT cmdlet)

    -Dave

    PS: ISHRemote sample code is on github.com/.../AddIshDocumentObj.cs

  • Hi Dave,

    Thank you changed to EDTPNG might have done the trick, change the code to the following .

    string myEdt1 = "EDTPNG";
    WebClient wc = new WebClient();
    byte[] bytes = wc.DownloadData(someUrl);
    MemoryStream ms = new MemoryStream(bytes);
    System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
    using (Image image = Image.FromStream(ms))
    {
    using (MemoryStream m = new MemoryStream())
    {
    image.Save(m, image.RawFormat);
    byte[] imageBytes = m.ToArray();
    m.Read(imageBytes, 0, (int)System.Convert.ToInt64(m.Length));
    bytes = imageBytes;
    m.Close();
    m.Dispose();
    }
    }
    userClientDocumentObj.Create(2878821, "ISHIllustration", ref guidid, ref version, language, "Default", xmlMetadata, myEdt1, bytes);