• Mao Elvis
  • 0 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 2
I have done to the classify an image with cURL mentioned in the Metamind for developing the predictive services. I'm thinking about create datasets, get datasets and train datasets from apex. Then I tried to get datasets from apex like from cURL and create a request like the example of pridicting image mentioned in the APEX QUICK START. but I got an http error like 'Status=GATEWAY_TIMEOUT, StatusCode=504', anyone know how to figure it out?
I want to download images posted in chatter group by push a button in visualforce page. The problem is that a few images are not downloaded when I use the way of opening the download link of image like ['/servlet/servlet.FileDownload?file=' + fileId] and put a interval in the loop.
Is anyone knows workaround? 


I'm trying to set up a Lightning app that will allow a user to provide a url to a zip file, have that zip file loaded as a dataset into the predictive vision service, then specify the newly created dataset to be trained into a datamodel. I'm able to load the data model from the menu, and get back a dataset id.

But I'm stuck on how to call the training service. I modified the provided VisionController code as follows:

    public static String postDatasetTrain(string datasetId, string datasetName) {
        // Get a new token
        JWT jwt = new JWT('RS256');
        jwt.cert = 'SelfSignedCert_18Jul2016_235259';
        jwt.iss = 'developer.force.com';
        jwt.sub = 'joseph.daily@careerbuilder.com';
        jwt.aud = 'https://api.metamind.io/v1/oauth2/token';
        jwt.exp = '3600';
        String access_token = JWTBearerFlow.getAccessToken('https://api.metamind.io/v1/oauth2/token', jwt);      
        String VISION_API = 'https://api.metamind.io/v1/vision';
        String DATA_TRAIN = VISION_API + '/train';
        string contentType = HttpFormBuilder.GetContentType();
        //  Compose the form
        string form64 = '';      
        form64 += HttpFormBuilder.WriteBoundary();
        form64 += HttpFormBuilder.WriteBodyParameter('name', datasetName);
        form64 += HttpFormBuilder.WriteBoundary();
        form64 += HttpFormBuilder.WriteBodyParameter('datasetId', datasetId);        
        form64 += HttpFormBuilder.WriteBoundary(HttpFormBuilder.EndingType.CrLf);
        blob formBlob = EncodingUtil.base64Decode(form64);
        string contentLength = string.valueOf(formBlob.size());
        //  Compose the http request
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setHeader('Connection', 'keep-alive');
        httpRequest.setHeader('Content-Length', contentLength);
        httpRequest.setHeader('Content-Type', contentType);
        httpRequest.setHeader('Authorization','Bearer ' + access_token);
        Http http = new Http();
        HTTPResponse res = http.send(httpRequest);
        system.debug('res: ' + res);
        system.debug('res.getBody(): ' + res.getBody());
        return res.getBody();


But the response that comes back is always a 403 : forbidden message.

Is there anything obvious causing this in my code?


I am at the step Create a custom classifier/Set up authorization/Generate a JWT token.
When I run the script jwt.sh I get a response:
             Your access token response:
              {"message":"Invalid JWT token"}

I am on win10 64bit but don't have the anniversary update so I don't have bash coming with win10.
I have bash came with git.
As I don't have a valid JWT token I can not continue to "Step 1: Create the Dataset".

Please help.

Here is a more detailed output and my changes to the jwt.sh script:

Script output (with my password changed)


$ ./jwt.sh ./00D0Y0000008amn.jks lajos.kelemen@accenture.com 3600 https://api.metamind.io
Enter destination keystore password:  my_pass
Enter source keystore password:  my_pass
Existing entry alias lkelemen_sf_devcert exists, overwrite? [no]:  yes
Entry for alias lkelemen_sf_devcert successfully imported.
Import command completed:  1 entries successfully imported, 0 entries failed or cancelled
[Storing privateKey.p12]
MAC verified OK

Generated Assertion:


Your access token response:

{"message":"Invalid JWT token"}


my script changes:

openssl pkcs12 -in privateKey.p12 -nocerts -nodes -out private_key
changed to (added -passin pass at the end)

openssl pkcs12 -in privateKey.p12 -nocerts -nodes -out private_key -passin pass:my_pass

curl -H "Content-type: application/x-www-form-urlencoded" -X POST "$4/v1/oauth2/token" -d \
"grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=$jwt3.$jwt5" ; echo

changed to (added -k parameter to accept self signed certs?)

curl -k -H "Content-type: application/x-www-form-urlencoded" -X POST "$4/v1/oauth2/token" -d \
"grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=$jwt3.$jwt5" ; echo