A388

Kraken.io API Implementation in C#

Kraken.io is an image optimization service. I use it at work as part of an automated task to optimize photos taken on job sites. As I'm writing this, we've uploaded 3.24 million photos with a raw file size of 2.08 TB which were optimized down to 1.05 TB or about 50% saved. Those savings go a long way when storing, especially in the cloud.

There is an official Kraken.io client for .NET, but I didn't really feel comfortable with it. It just looked overly complex, so I opted for creating my own client. When we first started using Kraken.io I had to make it as a scheduled task in Salesforce so I had to make my own client regardless. Eventually I ported it out of Salesforce and into our system because the Salesforce limitations and the amount of hoops I had to jump through to make it work were ridiculous. Porting it to .NET and into our system allowed me to make the automated process do what it needed to without worrying about limits and constraints.

I've since decided to extract it out into a standalone project and make it available as a NuGet package. The NuGet package targets .NET Standard 1.3, and the source code is available on GitHub, here.

To use the client simply create an instance of KrakenClient and pass in an instance of HttpClient and your API access and secret keys. For a short example of how it works, take a look at the linked video above.

On a side note, I really wish Kraken would just use a single API key like Carmine.io, Geocod.io and Google Maps, to name a few. The access and secret keys don't really do anything other than getting passed into requests. A single key would accomplish the same job. If there was an actual purpose to them like calculating a request signature like the AWS APIs, then they'd make sense, but they don't so it's an area where the API could be simplified in the future.

Let's get back on topic.

var kraken = new KrakenClient(
    httpClient,
    "{accessKey}",
    "{secretKey}"
);

Optimize

var optimize = await kraken.GetOptimizeAsync(
    "{filePath}"
);

Optimize Wait

var optimizeWait = await kraken.GetOptimizeWaitAsync(
    "{filePath}"
);

Download

var download = await kraken.DownloadAsync(
    "{krakedUrl}"
);
View or Start a DISQUS Thread