Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shrutis22
Created October 12, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrutis22/9998670233c8f547b812c388db5e8524 to your computer and use it in GitHub Desktop.
Save shrutis22/9998670233c8f547b812c388db5e8524 to your computer and use it in GitHub Desktop.
@RestResource( urlMapping = '/tesselservices/*' )
global class TesselServices {
public static final String MODEL_ID = 'INSERT MODEL ID HERE';
@HttpPost
global static String upload() {
RestRequest req = RestContext.request;
RestResponse res = Restcontext.response;
Blob picture = req.requestBody;
ContentVersion conVersion = new ContentVersion();
conVersion.Title = 'Content Version' + System.now().getTime();
conVersion.PathOnClient = 'file_' + Datetime.now().getTime() + '.jpg';
conVersion.VersionData = picture;
conVersion.Origin = 'H';
INSERT conVersion;
ContentDistribution cd = new ContentDistribution();
cd.Name = 'Content Dist ' + System.now().getTime();
cd.ContentVersionId = conVersion.Id;
cd.PreferencesAllowOriginalDownload = TRUE;
cd.PreferencesAllowPDFDownload = TRUE;
cd.PreferencesAllowViewInBrowser = TRUE;
INSERT cd;
List<ContentDistribution> conDist = new List<ContentDistribution>();
conDist = [
SELECT ContentDownloadUrl
FROM ContentDistribution
WHERE Id = :cd.Id
];
return conDist[0].ContentDownloadUrl;
}
@HttpGet
global static PredictionResponse authenticate() {
EinsteinAPI api = new EinsteinAPI();
PredictionResponse resp = api.predictImage( MODEL_ID, EncodingUtil.urlDecode( RestContext.request.params.get( 'img' ), 'UTF-8' ) );
return resp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment