> On 27 Apr 2017, at 14:57, Juraj Kubelka <juraj.kube...@icloud.com> wrote:
> 
> Hi,
> 
> That’s great! Thank you a lot for the information :-)

Well, it is Peter who came up with the alternative request. All credit to him.

> Juraj
> 
>> On Apr 27, 2017, at 09:52, Sven Van Caekenberghe <s...@stfx.eu> wrote:
>> 
>> 
>>> On 26 Apr 2017, at 17:21, Peter Uhnak <i.uh...@gmail.com> wrote:
>>> 
>>> Maybe the content is not properly stored in the JSON on github' side? But 
>>> you can use base64 in `accept:` to make it work.
>>> 
>>> json := STONJSON fromString: (ZnClient new
>>>                    url: 'https://api.github.com/gists/5503544';
>>>                    accept: 'application/vnd.github.v3.base64+json';
>>>                    get).
>>> b64 := ((json at: 'files') at: 'thumbnail.png') at: 'content'.
>>> PNGReadWriter formFromStream: (Base64MimeConverter mimeDecodeToBytes: 
>>> content readStream).
>> 
>> Ah, great that you found a way to force the server to send the data in a 
>> more sensible way !
>> 
>> Using the latest code from Zn & NeoJSON, combining with another recent 
>> thread (accessing nested dictionaries), this could be written as:
>> 
>> json := NeoJSONObject fromString: (ZnClient new
>>              url: 'https://api.github.com/gists/5503544';
>>              accept: 'application/vnd.github.v3.base64+json';
>>              get).
>> b64 := json atPath: #('files' 'thumbnail.png' 'content').
>> PNGReadWriter formFromStream: (ZnBase64Encoder new decode: b64) readStream.
>> 
>> Sven
>> 
>>> Peter
>>> 
>>> 
>>> On Wed, Apr 26, 2017 at 04:50:04PM +0200, Sven Van Caekenberghe wrote:
>>>> I am puzzled by how they actually encoded the PNG as a String, I tried a 
>>>> couple of alternatives but I could not get binary data out of it so that 
>>>> it parsed successfully as PNG.
>>>> 
>>>> If I would have to encode binary data in JSON I would use Base64 encoding 
>>>> (but alternatives exist).
>>>> 
>>>>> On 24 Apr 2017, at 20:36, Juraj Kubelka <juraj.kube...@icloud.com> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> I was playing with GitHub Gist API and I have queried the following Gist: 
>>>>> https://gist.github.com/mbostock/5503544
>>>>> I was interested how the PNG image is returned: 
>>>>> https://gist.github.com/mbostock/5503544#file-thumbnail-png 
>>>>> 
>>>>> I can obtain the whole Gist executing:
>>>>> 
>>>>> STONJSON fromString: 
>>>>>   (ZnClient new
>>>>>           url: 'https://api.github.com/gists/5503544';
>>>>>           accept: 'application/vnd.github.v3+json';
>>>>>           get).
>>>>> 
>>>>> I can get PNG contents executing:
>>>>> 
>>>>> pngData := (ZnEasy get:
>>>>>   ((((STONJSON fromString: 
>>>>>           (ZnClient new
>>>>>                   url: 'https://api.github.com/gists/5503544';
>>>>>                   accept: 'application/vnd.github.v3+json';
>>>>>                   get)) at: 'files') at: 'thumbnail.png') at: 'raw_url')) 
>>>>> contents.
>>>>> PNGReadWriter formFromStream: rawPng readStream.
>>>>> 
>>>>> But the PNG image is part of the Gist query and can be retrieved by:
>>>>> 
>>>>> pngContent := ((((STONJSON fromString: 
>>>>>   (ZnClient new
>>>>>           url: 'https://api.github.com/gists/5503544';
>>>>>           accept: 'application/vnd.github.v3+json';
>>>>>           get)) at: 'files') at: 'thumbnail.png') at: 'content').
>>>>> 
>>>>> "As pngContent is a WideString, I cannot use:"
>>>>> PNGReadWriter formFromStream: pngContent readStream.
>>>>> 
>>>>> How can I read the PNG image from the pngContent? Any idea? 
>>>>> And the reverse question: How can I send the PNG bytes using JSON format? 
>>>>> 
>>>>> Thanks!
>>>>> Juraj
>>>>> 
>>>> 
>>>> 
>>> 
>> 
>> 
> 
> 


Reply via email to