Question

Looker returns PNG/JPG as a String, which Charset?

  • 12 December 2017
  • 4 replies
  • 212 views

After generating the SDK by hand I still can’t fill in the blanks for requesting looks as an image.


Swagger can render the image. When calling programatically, such as



lookApi.runLook(3L, “png”, 300L, FALSE, FALSE, FALSE, 1024L, 512L, FALSE, FALSE, FALSE, “”, FALSE, FALSE);



We see the following garbage printed. How can this be decoded? Is it Base64? Is PhantomJS opening a browser and taking a screenshot? What should the character encoding be for the request?


‰PNG


IHDR ¾

åv! pHYs šœ IDATxœìÝ}”•u¡/ðïÌ03¼¯:ƒ‚‚o¤ “¢£T$­(¯éI]½Ü\®Ûiy

¯yº‡Õ9e–ë˜×jõv5¯å­S

T,õ(Ò-ñ(‚t”

JËA1Æ᝙a˜û‡±„!±7Œãóùü5ûù=û7ß=ºöb÷ï÷<UÝÝÝÝ ÞÔª{: °ï) P

( €

@ €P @( úôt ÞX.™¿¢§#@áÜrÖøžŽ @X €P @( P

( €

@ €P @( P

( €

@ €P @( P

(€>=OmÙ²%÷Þ{o}ôÑ$Éa~ðƒillÜåÜE‹å®»îJggg&Nœ˜‹/¾8ÕÕÕéîîΜ9s²xñâÔÔÔdƌ™:uj’ìv z»^³Û¶m9à€òùÏ>×]w]&Ožœüàa»œ÷ÒK/åÎ;ïÌ’?ùÉ|ñ‹_LGGGæϟŸä•bàÙgŸÍµ×^›ú§ÊÏþó<óÌ3¯; ½]¯)

”ÓN;-µµµI’£>:­­­»œ·|ùòœ|òÉ1bDjjjröÙg—V

,]º4Ó§OO]]]3Î8#=öØëŽ @o×k

€WÛ´iS~üãç”SNÙeìÅ_LSSSéqcccZZZ’$kÖ¬ÙiË@ccc^xá

× €Þ®×\ I^~ùå|á_Ȇ

erÌ1ÇäôÓOß圎ŽŽÒ*$©©©ÉöíÛÓÕÕµËX]]]ÚÛÛ_óy¯ €Þ®W C‡Íÿú_ÿ+Û¶m˒%KrÝu×åꫯNMMMéœúúúlݺµô¸££#UUU©©©Ùel˖-©««{Íç½zl‡¶¶¶}õҀóÞ @9†²Gçõª‡>}úäoþæo2oÞ¼´µµeøðᥱ¦¦¦Ò’ÿä•-;–öïÛ±E ¥¥eÆvØÓ?jïö\Oa€Â)Æ{ =­×\àÅ_Üé[²'žx"ÝÝÝ6lX:;;K<ᄲtéÒüñLWWWî¿ÿþLš4)I2yòä,X° Ù´iS.\¸Gc ÐÛõš ëÖ­Ëm·Ý– e6¤¦¦&¹ì²ËRUU•e˖eá ¹òÊ+3tèМþù¹á†eÒÞޞñãÇgƌI^ù¿zõê̞=;UUU™6mZƍe÷ºc ÐÛUuwww÷tˆr͝;7Æ ËÔ©S{:J¯wÉü= 疳Æ÷t ×l؝æææœtÒI= Þ°z̀ݙ5kVOG €7´7Å÷ P

( €

@ €P @( P

( €

@ €P @( P

( €

@ €P @( P

( €

@ €P @( P

( €

@ €P @( P

(€>=Omß¾=÷Þ{oyä‘tuueäȑùàa?˜áÇïrîe—]–êêÿì6>úяfâĉéîîΜ9s²xñâÔÔÔdƌ™:uj’ìv z»^S lݺ5ÕÕÕùÇüÇôë×/÷Ýw_~ô£åcûØ.ç e6,ŸûÜçv™cÑ¢EyöÙgsíµ×¦³³3×_}ƌ“±cÇîv z»^³ ÿþ9çœsÒ¯_¿$Éñǟ–––]Î[¿~}^sŽ¥K—fúôé©««Ë€rÆgä±Ç{Ý1 èízÍ €?÷»ßýî5¿oooOsss>ó™Ï¤««+&Lȹ瞛úúú¬Y³&¥seee³|ùò$Ùí ôv½² X·n]æϟŸË/¿|—±Ñ£Gçºë®Kß¾}³e˖üð‡?ÌܹssÑE¥££#µµµ¥sëêêÒÞޞ$» €Þ®× ›7oÎ׿þõ\pÁ1bÄkžÓ·oß$I¿~ý2sæÌ|éK_J’Ô××gëÖ­¥ó¶lْººº×Û¡­­­¢¯ ñÞ @y†²GçõªëÖ­ùÚ×¾–éÓ§g„ {ôœ®®®Òaù¦¦¦´´´¤©©)IÒÒÒRZö¿»±öôÚ»=×Ó pŠñÞ

/snip


4 replies

Userlevel 2

Hi @ryeates,


Where are you seeing this? Are you outputting the results directly to the console? If so, that won’t work since most shells don’t know how to interpret png files. Try writing the contents of the return to a .png file. Here is my code using the Ruby SDK after creating a look render task, waiting for it to complete, then getting the results and putting it into a .png file


...
results = sdk.render_task_results(id)

File.open('look.png', 'w') { |file| file.write(results) }

Here is a more detailed example of generating a png for a Look.


Cheers,

Vincent

Hi,


This doesn’t answer any of the questions asked. The example provided is for a different api endpoint and in a different language.


With trial and error the following is a working example in Java. Adding it here for anyone trying to use the Looker API with Java.


import static java.lang.Boolean.FALSE;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;

import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import io.swagger.client.ApiClient;
import io.swagger.client.ApiException;
import io.swagger.client.api.ApiAuthApi;
import io.swagger.client.api.LookApi;
import io.swagger.client.model.AccessToken;

public class GetLookImage {

public static void main(String[] args) throws ApiException, IOException {
ApiClient apiClient = new ApiClient();
apiClient.setVerifyingSsl(false); //should be enabled in prod
apiClient.getHttpClient().setReadTimeout(10L, TimeUnit.MINUTES); //because looker seems quite slow
apiClient.setBasePath("https://localhost:19999/api/3.0/");

ApiAuthApi apiAuthApi = new ApiAuthApi(apiClient);

AccessToken accessToken = apiAuthApi.login("id", "secret");
apiClient.addDefaultHeader("Authorization","token " +accessToken.getAccessToken());

LookApi lookApi = new LookApi(apiClient);

// auto generated code which looks terrible
String image = lookApi.runLook(3L, "png", 300L, FALSE, FALSE, FALSE, 1024L, 512L, FALSE, FALSE, FALSE, "", FALSE, FALSE);
// have to manually specify the charset, this works but was guessed as there is no documentation available
FileUtils.writeStringToFile(new File("image.png"), image, StandardCharsets.UTF_8);
}

}

The question remains - is the reason for the slow performance due to PhantomJS effectively taking a screenshot?

Userlevel 2

Hi @ryeates,


Thank you for the clarifying. Clearly this is a performance issue and I miss understood and assumed this was a rendering issue. When running the run_look endpoint with a result format of type png, there are a few more gears turning on the backend than running a look and taking a screenshot. Running or generating queries or checking for them in cache, creating render tasks, generating a png from the query result, waiting for that to complete, then getting the result of that render task.


I can understand the frustration of it taking longer than expected. I am curious to know, however, how long it is taking to complete everything? I have a JAVA SDK on my machine and can run tests and compare our results.


Cheers,

Vincent

Hi Vincent,


I’m currently testing and will come back with my observations.


Cheers,


Rob

Reply