Skip to content

Instantly share code, notes, and snippets.

@TimonVS
Last active February 23, 2016 18:07
Show Gist options
  • Select an option

  • Save TimonVS/d91bd2d2301beec47c0b to your computer and use it in GitHub Desktop.

Select an option

Save TimonVS/d91bd2d2301beec47c0b to your computer and use it in GitHub Desktop.

Uploadcare

Uploadcare provides the ability for users to upload files from any cloud storage provider. Uploadcare also provides other functionality such as cropping images.

Implementation in the back-end

For now we will use the storage of Uploadcare, this will probably change in the future. To protect the files we will use a custom CDN with signed URLs, you can read more about this in their knowledge base.

In the future we might want to use our own storage to store the attachments the user uploads with Uploadcare. Uploadcare would provide us with a temporary link (valid for 24 hours) to the file. You can read more about this in their documentation about storage.

If a user uploads an item with the Uploadcare widget we get back a response like:

{
  "uuid": "e350b8f2-ba54-4dd9-8a73-e13ff54ff416",
  "name": "icon.png",
  "size": 15122,
  "isStored": true,
  "isImage": true,
  "originalImageInfo": {
    "orientation": null,
    "format": "PNG",
    "height": 128,
    "width": 128,
    "geo_location": null,
    "datetime_original": null
  },
  "originalUrl": "https://ucarecdn.com/e350b8f2-ba54-4dd9-8a73-e13ff54ff416/",
  "cdnUrl": "https://ucarecdn.com/e350b8f2-ba54-4dd9-8a73-e13ff54ff416/",
  "cdnUrlModifiers": null,
  "sourceInfo": {
    "source": "local",
    "file": {}
  }
}

What we will send to the API is:

{
   "type":"item",
   "owner":{
      ...
   },
   "description":"<p>Description</p>",
   "labels":[
      ...
   ],
   "privacy_level":"organization",
   "attachments":[
      {
         "type":"image",
         "url":"https://ucarecdn.com/826f978d-b9bd-4d7b-a516-3d60030c8dc9/",
         "title":"icon.png",
         "origin":"uploadcare"
      },
      {
         "type":"file",
         "url":"https://ucarecdn.com/4c11de43-fcf2-4bfc-8cf2-ec74c4a3b98d/",
         "title":"Label A office info 010.pdf",
         "origin":"uploadcare"
      }
   ],
   "draft":false
}

The back-end will need to generate the thumbnails just like it does for normal uploads. Although the Uploadcare CDN API provides a way to transform images to your liking, you can read more about this in their documentation.

@desmax
Copy link
Copy Markdown

desmax commented Feb 23, 2016

I push first version, take a look, is that what you expected?
I expected these types:
'type' => 'uploadcare',
'uploadcare_type' => ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment