Digital Media Suite API Forums

Combination View Flat View Tree View
Threads [ Previous | Next ]
Hello,
  I am having trouble adding an asset to the DMM via the API.  I am using the POST - /xTAS-core/services/content/asset/ method and the DMM is returning 404 Not Found.  Attached is a wireshark packet capture.  It's not really a .txt file, so FYI. The forum interface won't allow me to makeup a file extension.
 
Thanks,
Matt
Attachments:

Hi Matt,
 
You are facing the same issue we are facing. I most probably know the reason, but not the solution yet. DMM must be able to resolve the URL you are posting. In your request, you are adding an asset that points to /tmp/file.html. It will give you the error you are getting because DMM wants to resolve it via DNS.
 
Are you looking for uploading and asset or adding an asset from URL. My problem is adding an asset that point to a local file on DMP file system. /tmp/usb_1/file.mpg
 
-Walid

Hi Walid,   
According to the API Guide (version 0.7.3), there are 2 APIs for adding/uploading an asset.
1)Upload an asset (file)
2)Add an asset from a URL
 
I am using #1.  The only difference in the two API's is the xml:storageType parameter.  There is another parameter that looks suspicious to me.  I wonder if the xml:downloadurl parameter should be 'false' instead of 'true'.  Anyway, the way I understand it, the DMM should pull the file out of the POST body for API #1, not attempt to download it from a URL.  Can anyone from Cisco verify this?
 
Thanks, Matt
 
Cisco Developer Community Forums wrote: Walid Azab has created a new message in the forum "Digital Signs API Forum": -------------------------------------------------------------- Hi Matt,   You are facing the same issue we are facing. I most probably know the reason, but not the solution yet. DMM must be able to resolve the URL you are posting. In your request, you are adding an asset that points to /tmp/file.html. It will give you the error you are getting because DMM wants to resolve it via DNS.   Are you looking for uploading and asset or adding an asset from URL. My problem is adding an asset that point to a local file on DMP file system. /tmp/usb_1/file.mpg   -Walid -- To respond to this post, please click the following link: <http://developer.cisco.com/web/dms/forums/-/message_boards/message/2110401> or simply reply to this email. -- Matt Stromske Software Engineer Singlewire Software, LLC www.singlewire.com ------------------ 608.661.1178 matt.stromske@singlewire.com

Hi Matt,

Page 15 of the api documentat titled "API Programmer Guide for Cisco Digital Signs" explains how to upload an asset from a file. This is different than the other API calls as you can not simply paste the REQUEST section of this API into the body of your POST, rather,  you must upload an asset using a multi-part form. This can be most simply done by following the steps below:

1. create a HTML file locally with the sample HTML given in the REQUEST section of the call. You can do this in windows by opening notepad, or any other text editor, pasting the HTML sample code text, and then making sure to name your file extension ".html". Make sure you replace the html text that says "____YOUR_HOSTNAME____" with your actual hostname.
2. Once you have saved the file, open it using a web browser. You should see a "File to upload" box to which you can upload a locally stored file.
3. Below the upload box, you will see a large text area with a label "data". Looking back to page 14 of the API documentation, you will see an xml template in the REQUEST section under the sample HTML code. Paste this xml into the "data" textbox.
4. Enter the ASSET TITLE, ASSET FILE NAME, ASSET DESCRIPTION, VALID FILE TYPE, CATEGORY ID, and USER NAME into the xml template as appropriate. Be sure to enter a valid file type as listed under the PREREQUISITES section of this call. You can obtain the category id by using the Get Category Tree API call on page 14.
5. Click the upload button.

Done. At this point you should have successfully uploaded a locally stored asset to the DMM.
 
You reach the same results programmatically by creating a multi-part form, and uploading a file. The details of how to accomplish this will vary depending on the language you are programming in.


Hope that helps
-Hashir

Thanks for the response.  Maybe I wasn't clear in my previous messages.  If you look at the attached packet capture, you'll see I am using the multipart form as the API indicates.  The first part is the file part and the second part is the XML part.  I am doing this programmatically (no html page).   I am still getting 404 NOT FOUND.
 
My next plan is to use the HTML page and capture the packets to see if there is a difference.
 
Thanks,
Matt

Hi Matt,
 
Could you go ahead and try creating the HTML page and seeing if you are able to upload using that? The process is relatively straightforward, and it will help us determine whether the API call/documentation is the issue or something in your environment. While I am able to do this on my end, if you have a corner case that is not working for some reason we will be able to quickly identify it if you are unable to.
 
 
-Hashir

Hi Hashir,
  I tried using the HTML page to upload the asset and it worked.  It flushed out one problem for me: I was not using the correct category ID.  However, after fixing the category ID, my attempt at uploading the asset programmatically still fails with a 404 NOT FOUND.  I performed packet captures for both the HTML page upload and the programmatic method used my my code.  They are both attached to this thread.  The main difference I see is encoding of the file.  In the HTML page upload, the browser encodes the file in "line-based text."  My code does not do this.  It encodes the file in binary.  My Java code is using HttpClient 4.0.  Do you have sample code that works for this?  If so, I'd like to see it.
Attachments:

Matt,
 
It looks like we have not tested this using the version of HttpClient that you are using. We are going to try do this to reproduce the issue on our end. I will get back to you with the results.
 
 
-Hashir

Any progress on this?
 
Thanks,
Matt

We should have an update for this by early next week.
 
-Hashir

Matt,

Since I last posted on this thread, we have tested HttpClient 3.0. I have pasted (tested) sample code that will work once you edit variables that are specific to your instance of DMM (marked clearly in the code with comments). Please give this a try. I have also attached the Java file to this post for your convenience (you will need to change the extension to .java).

-Hashir
 
 
Sample code below
--------------------------------------------------------------
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///ENTER IN YOUR INSTANCE SPECIFIC DATA BELOW
       
        String dmmDomainName = "dmmServer.someCompanny.com";
       
        String usernameOfUploader = "adminUsername";
        String passwordOfUploader = "adminPassword";
       
        String fileName = "someImage.jpg";//This example uploads an image
        String assetDescription = "AssetDescription";
        String fileType = "IMAGES";//This does not need to be changed if you are uploading an image
        String categoryId = "6";//6 is usually the category for images
       
        String filePath = "C:\\Documents and Settings\\user\\images\\" + fileName;
       
       
///YOU DO NOT NEED TO MODIFY ANY CODE BELOW THIS LINE
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
       
        //Create an instance of HttpClient.
        HttpClient client = new HttpClient();
       
        //authentication.
        client.getParams().setAuthenticationPreemptive(true);
        Credentials defaultCreds = new UsernamePasswordCredentials(usernameOfUploader, passwordOfUploader);
        client.getState().setCredentials(new AuthScope(dmmDomainName, 8080, AuthScope.ANY_REALM), defaultCreds);
       
        //Create an instance of one of the methods (PostMethod in this case). The URL to connect to is passed in to the the method constructor.         
         PostMethod filePost = new PostMethod("http://" + dmmDomainName + ":8080/xTAS-core/services/content/assets/");
         
         //set xml data as a variable
         String xmlData = "<n1:asset xmlns:n1=\"http://www.cisco.com/dms/xml/ns/dsm/contentManagement\">" +
         " <title>AssetTitle</title>" +
         " <fileName>" + fileName + "</fileName>" +
         " <description>" + assetDescription + "</description>" +
         " <fileType>" + fileType + "</fileType>" +
         " <estimatedDuration>" +
         " <Hours>0</Hours>" +
         " <Minutes>0</Minutes>" +
         " <Seconds>0</Seconds>" +
         " </estimatedDuration>" +
         " <categoryIdList>" +
         " <id>" + categoryId + "</id>" +
         " </categoryIdList>" +
         " <assetOwner>" + usernameOfUploader + "</assetOwner>" +
         " <storageType>file</storageType>" +
         " <downloadurl>true</downloadurl>" +
         " </n1:asset>";

         //create a File part. This will be one part of a multipart form
         File f = new File(filePath);
         FilePart filePart = null;
         try {
             filePart = new FilePart("upload_file", f);
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         }
         
         //String part. This is another part of a multipart form
         StringPart stringPart = new StringPart("data", xmlData);
         
         //Place all parts into a Parts array
         Part[] parts = {
                 filePart,
                 stringPart
         };
         
         //create the multipart form
         filePost.setRequestEntity(
             new MultipartRequestEntity(parts, filePost.getParams())
             );
         
        //execute post
        try {
            client.executeMethod(filePost);
        } catch (HttpException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
       
        //Read the response.
        String responseBody = null;
        try {
            responseBody = filePost.getResponseBodyAsString();
        } catch (IOException e) {
            e.printStackTrace();
        }
       
        //Release the connection.
        filePost.releaseConnection();
       
        //Deal with the response.
        System.out.println(responseBody);
        filePost.releaseConnection();
         
    }

}
Attachments:

Thanks Hashir.   That code works.  I'm not sure why Httpclient 4.0.1 doesn't seem to work.  I followed their multipart form example to the letter.  Anyway, I will change my code to use Httpclient 3.0 and will go from there.
 
Thanks again.
 
Matt

Hashir,
 
   Just a FYI:  the API for 'Upload an Asset' in the Programmer's Guide is incorrect.  This might apply to 'Add Asset from URL' as well.   The URL in the Programmer's Guide is:
/xTAS-core/services/content/asset/
 
The URL in the sample code you sent me:
/xTAS-core/services/content/assets/
 
Note the extra 's' in your URL.  This explains why I was getting a '404 Not Found' when I was testing with HttpClient 4.0.
 
Thanks,
Matt
 
 
 
Matt,

Since I last posted on this thread, we have tested HttpClient 3.0. I have pasted (tested) sample code that will work once you edit variables that are specific to your instance of DMM (marked clearly in the code with comments). Please give this a try. I have also attached the Java file to this post for your convenience (you will need to change the extension to .java).

-Hashir
 
 
Sample code below
--------------------------------------------------------------
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///ENTER IN YOUR INSTANCE SPECIFIC DATA BELOW
       
        String dmmDomainName = "dmmServer.someCompanny.com";
       
        String usernameOfUploader = "adminUsername";
        String passwordOfUploader = "adminPassword";
       
        String fileName = "someImage.jpg";//This example uploads an image
        String assetDescription = "AssetDescription";
        String fileType = "IMAGES";//This does not need to be changed if you are uploading an image
        String categoryId = "6";//6 is usually the category for images
       
        String filePath = "C:\\Documents and Settings\\user\\images\\" + fileName;
       
       
///YOU DO NOT NEED TO MODIFY ANY CODE BELOW THIS LINE
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
       
        //Create an instance of HttpClient.
        HttpClient client = new HttpClient();
       
        //authentication.
        client.getParams().setAuthenticationPreemptive(true);
        Credentials defaultCreds = new UsernamePasswordCredentials(usernameOfUploader, passwordOfUploader);
        client.getState().setCredentials(new AuthScope(dmmDomainName, 8080, AuthScope.ANY_REALM), defaultCreds);
       
        //Create an instance of one of the methods (PostMethod in this case). The URL to connect to is passed in to the the method constructor.         
         PostMethod filePost = new PostMethod("http://" + dmmDomainName + ":8080/xTAS-core/services/content/assets/");
         
         //set xml data as a variable
         String xmlData = "<n1:asset xmlns:n1=\"http://www.cisco.com/dms/xml/ns/dsm/contentManagement\">" +
         " <title>AssetTitle</title>" +
         " <fileName>" + fileName + "</fileName>" +
         " <description>" + assetDescription + "</description>" +
         " <fileType>" + fileType + "</fileType>" +
         " <estimatedDuration>" +
         " <Hours>0</Hours>" +
         " <Minutes>0</Minutes>" +
         " <Seconds>0</Seconds>" +
         " </estimatedDuration>" +
         " <categoryIdList>" +
         " <id>" + categoryId + "</id>" +
         " </categoryIdList>" +
         " <assetOwner>" + usernameOfUploader + "</assetOwner>" +
         " <storageType>file</storageType>" +
         " <downloadurl>true</downloadurl>" +
         " </n1:asset>";

         //create a File part. This will be one part of a multipart form
         File f = new File(filePath);
         FilePart filePart = null;
         try {
             filePart = new FilePart("upload_file", f);
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         }
         
         //String part. This is another part of a multipart form
         StringPart stringPart = new StringPart("data", xmlData);
         
         //Place all parts into a Parts array
         Part[] parts = {
                 filePart,
                 stringPart
         };
         
         //create the multipart form
         filePost.setRequestEntity(
             new MultipartRequestEntity(parts, filePost.getParams())
             );
         
        //execute post
        try {
            client.executeMethod(filePost);
        } catch (HttpException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
       
        //Read the response.
        String responseBody = null;
        try {
            responseBody = filePost.getResponseBodyAsString();
        } catch (IOException e) {
            e.printStackTrace();
        }
       
        //Release the connection.
        filePost.releaseConnection();
       
        //Deal with the response.
        System.out.println(responseBody);
        filePost.releaseConnection();
         
    }

}

Matt,
 
I've uploaded new documentation after putting in the fix to the error regarding the incorrect URL. All instances where the URL was incorrectly stated as /xTAS-core/services/content/asset/ have been updated to /xTAS-core/services/content/assets/
 
-Hashir

Hi Hashir,

I have copied and pasted your code into my code, changed the parameters but I got this error message:

1
2<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:result xmlns:ns2="http://www.cisco.com/dms/xml/ns/dsmCommonService" xmlns:ns3="http://www.cisco.com/dms/xml/ns/historyManagement"><status>failure</status><code>Bad Request</code><description>Cannot add content Desert.jpg: there was an exception in adding asset</description></ns2:result>


The file "Desert.jpg" is at the location specified.

Any ideas why DMM returned an upload failure?

Thanks.

Found the cause of the error: Category id shoud be 2 for images, not 6.