0

Ive just started taking a look at the uploadcare product and its api.

Ive just realized that the API only seems to allow you to upload files with no way of viewing a listing of the files once they are uploaded.

Would anyone happen to know if its possible to use the widget to retrieve a listing of files that has been uploaded ?

David Avsajanishvili
  • 7,678
  • 2
  • 22
  • 24
user125264
  • 1,809
  • 2
  • 27
  • 54
  • 3
    I just searched for ["uploadcare api list files"](https://duckduckgo.com/?q=uploadcare+api+list+files). The first hit is their [rest api documentation](https://uploadcare.com/documentation/rest/) and includes a reference to `GET /files/` - you've either not shown any effort or are not being clear in explaining what you're trying to do... – Peter Boughton Feb 14 '14 at 10:32
  • nope definitely been searching alot on this topic, i guess i just assumed that someone who makes a file upload service would provide a simple jquery library to retrieve files from their cdn. i was mistaken – user125264 Feb 14 '14 at 10:35
  • 2
    It's a REST API - so [`jQuery.ajax`](http://api.jquery.com/jQuery.ajax/)`('https://api.uploadcare.com/files/',{headers:[authstuff]}).always(FuncToHandleResponse)` – Peter Boughton Feb 14 '14 at 10:37

2 Answers2

4

Based on mojo's answer regarding REST requiring private keys, here's a quick proof of concept of how you can do a back-end proxy in CFML:

<cfhttp method="GET" url="https://api.uploadcare.com/files/">
    <cfhttpparam type="header" name="Accept"        value="application/vnd.uploadcare-v0.3+json" />
    <cfhttpparam type="header" name="Date"          value="Fri, 09 Feb 2013 01:08:47 -0000" />
    <cfhttpparam type="header" name="Authorization" value="Uploadcare.Simple demopublickey:demoprivatekey" />
    <cfloop index="Key" collection=#Url# >
        <cfhttpparam type="url" name=#Key# value=#Url[Key]# />
    </cfloop>
    <cfloop index="Key" collection=#Form# >
        <cfhttpparam type="formfield" name=#Key# value=#Form[Key]# />
    </cfloop>
</cfhttp>

<cfloop index="HeaderName" collection=#cfhttp.ResponseHeader# >
    <cfheader name=#HeaderName# value=#cfhttp.ResponseHeader[HeaderName]# />
</cfloop>

<cfcontent type="application/json" />
<cfoutput>#cfhttp.FileContent#</cfoutput>

Again, it's proof of concept not finalised code, but should demonstrate the idea of how you can do it.

Community
  • 1
  • 1
Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
0

Simple answer is "You can't do it".

More complex answer is "You can, but you have to do things" (read below).

As already stated, you can get list of files via REST API. To make request to REST API you have to provide both public and secret keys. Widget does not support listing files as it uses only public key.

Of course you can make API request via AJAX, but you'll expose your secret key, and this will be on your conscience :).

What you should do is, build a backend view that fetches file list via REST, and makes it available to you frontend. Then you can add custom dialog tab that will show the list (somewhat similar is done in customization tutorial with "favorite files").

Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31