Nabs
Nabs

Reputation: 553

How to upload a file from Salesforce Apex to IBM Watson

I am trying to upload a sample document from Salesforce Apex class to IBM Watson. I am trying with the following snippet but am getting this error

"23:13:17:000 USER_DEBUG "error" : "Request timed out, please try again."

Somehow it is getting timed out.

        Blob fileBlob = Blob.valueOf('This is a sample pdf file');
        IBMDiscoveryV1 discovery = new IBMDiscoveryV1('2017-11-07');
        IBMDiscoveryV1Models.AddDocumentOptionsBuilder builder = new IBMDiscoveryV1Models.AddDocumentOptionsBuilder(
                '<<EnvironmentId>>',
                '<<CollectionId>>');

        IBMWatsonFile.FileBuilder fileBuilder = new IBMWatsonFile.FileBuilder();
        fileBuilder.name('Sample.pdf');
        fileBuilder.body(fileBlob);
        IBMWatsonFile file = fileBuilder.build();
        builder.file(file);

        IBMDiscoveryV1Models.AddDocumentOptions options = builder.build();

        IBMDiscoveryV1Models.DocumentAccepted docAccepted = discovery.addDocument(options);

Upvotes: 1

Views: 89

Answers (2)

German Attanasio
German Attanasio

Reputation: 23663

There was a problem with the IBM Watson Salesforce SDK and that's why you were getting a timeout. The issue was fixed in this pull request and released in v1.4.0.

The problem was that we were sending the wrong mime-type (APPLICATION_OCTET_STREAM) and we were not sending the filename in the multi-part request.

Upvotes: 1

muenzpraeger
muenzpraeger

Reputation: 373

If you see this error persistently please file an issue on the SDK's GitHub repo.

https://github.com/watson-developer-cloud/salesforce-sdk/issues

Upvotes: 0

Related Questions