Zinc newbie question: How to get file metadata from Dropbox

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
jb
Reply | Threaded
Open this post in threaded view
|

Zinc newbie question: How to get file metadata from Dropbox

jb
Hi!

To download a file from Dropbox is easy:

ZnClient new
  https; host: 'content.dropboxapi.com';
  addPath: '2'; addPath: 'files'; addPath: 'download';
  headerAt: 'Authorization' put:
   'Bearer <my generated access token>';
  headerAt: 'Dropbox-API-Arg' put: '{"path": "/demo.txt"}' ;get.

But I cannot figure out how to get file metadata
(https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata).

If I try the following

(ZnClient new
  https; host: 'api.dropboxapi.com';
  addPath: '2'; addPath: 'files'; addPath: 'get_metadata';
  headerAt: 'Authorization' put:
   'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7';
  headerAt: 'Content-Type' put: 'application/json';
  formAt: 'path' put: 'demo.txt'; post).

I get the error message from Dropbox:

Error in call to API function "files/get_metadata": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded".  Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".

Probably I am using ZnClient wrongly.

Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Zinc newbie question: How to get file metadata from Dropbox

Sven Van Caekenberghe-2

> On 20 Jul 2017, at 19:57, Johannes Brauer <[hidden email]> wrote:
>
> Hi!
>
> To download a file from Dropbox is easy:
>
> ZnClient new
>  https; host: 'content.dropboxapi.com';
>  addPath: '2'; addPath: 'files'; addPath: 'download';
>  headerAt: 'Authorization' put:
>   'Bearer <my generated access token>';
>  headerAt: 'Dropbox-API-Arg' put: '{"path": "/demo.txt"}' ;get.
>
> But I cannot figure out how to get file metadata
> (https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata).
>
> If I try the following
>
> (ZnClient new
>  https; host: 'api.dropboxapi.com';
>  addPath: '2'; addPath: 'files'; addPath: 'get_metadata';
>  headerAt: 'Authorization' put:
>   'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7';
>  headerAt: 'Content-Type' put: 'application/json';
>  formAt: 'path' put: 'demo.txt'; post).
>
> I get the error message from Dropbox:
>
> Error in call to API function "files/get_metadata": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded".  Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".

By using #formAt:put: you implicitly create a ZnApplicationFormUrlEncodedEntity instance, this is not what you want/need. This would POST proper JSON:

ZnClient new
 https; host: 'api.dropboxapi.com';
 addPath: '2'; addPath: 'files'; addPath: 'get_metadata';
 headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7';
 entity: (ZnEntity with: (STONJSON toString: { #path->'demo.txt' } asDictionary) type: ZnMimeType applicationJson);
 post.

Does that work ?

> Probably I am using ZnClient wrongly.
>
> Johannes


jb
Reply | Threaded
Open this post in threaded view
|

Re: Zinc newbie question: How to get file metadata from Dropbox

jb
Sven Van Caekenberghe-2 wrote
> On 20 Jul 2017, at 19:57, Johannes Brauer <[hidden email]> wrote:
>
> Hi!
>
> To download a file from Dropbox is easy:
>
> ZnClient new
>  https; host: 'content.dropboxapi.com';
>  addPath: '2'; addPath: 'files'; addPath: 'download';
>  headerAt: 'Authorization' put:
>   'Bearer <my generated access token>';
>  headerAt: 'Dropbox-API-Arg' put: '{"path": "/demo.txt"}' ;get.
>
> But I cannot figure out how to get file metadata
> (https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata).
>
> If I try the following
>
> (ZnClient new
>  https; host: 'api.dropboxapi.com';
>  addPath: '2'; addPath: 'files'; addPath: 'get_metadata';
>  headerAt: 'Authorization' put:
>   'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7';
>  headerAt: 'Content-Type' put: 'application/json';
>  formAt: 'path' put: 'demo.txt'; post).
>
> I get the error message from Dropbox:
>
> Error in call to API function "files/get_metadata": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded".  Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".

By using #formAt:put: you implicitly create a ZnApplicationFormUrlEncodedEntity instance, this is not what you want/need. This would POST proper JSON:

ZnClient new
 https; host: 'api.dropboxapi.com';
 addPath: '2'; addPath: 'files'; addPath: 'get_metadata';
 headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7';
 entity: (ZnEntity with: (STONJSON toString: { #path->'demo.txt' } asDictionary) type: ZnMimeType applicationJson);
 post.

Does that work ?
yes, it does

thanks a lot