Heroku add-on

Uploadcare is an add-on that handles uploading, storing and processing files.

Uploadcare is a service that helps media creators, businesses and developers receive, store, process and deliver visual content to their clients.

Uploadcare is accessible via an API and has supported client libraries for iOS, Python, Ruby, PHP, Node.js, Java, Erlang. Also there are plugins for Wordpress, CKEditor and tinymce.

Provisioning the add-on

Uploadcare can be attached to a Heroku application via the CLI:

callout A list of all plans available can be found here.

heroku addons:add uploadcare
-----> Adding uploadcare to sharp-mountain-4005... done, v18 (free)

Once Uploadcare has been added two API keys will be available in the app configuration:

  • UPLOADCARE_PUBLIC_KEY
  • UPLOADCARE_SECRET_KEY

This can be confirmed using the heroku config:get command.

heroku config:get UPLOADCARE_PUBLIC_KEY
your-public-api-key
heroku config:get UPLOADCARE_SECRET_KEY
your-secret-api-key

After installing Uploadcare the application should be configured to fully integrate with the add-on.

Local setup

Environment setup

After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.

callout Though less portable it’s also possible to set local environment variables using export UPLOADCARE_PUBLIC_KEY=value; export UPLOADCARE_SECRET_KEY=value.

Use Foreman to configure, run and manage process types specified in your app’s Procfile. Foreman reads configuration variables from an .env file. Use the following command to add the UPLOADCARE_PUBLIC_KEY and UPLOADCARE_SECRET_KEY values retrieved from heroku config to .env.

heroku config -s | grep UPLOADCARE >> .env
more .env

warning Credentials and other sensitive configuration values should not be committed to source-control. In Git exclude the .env file with: echo .env >> .gitignore.

Using with Rails 4.x

Installation

Ruby on Rails applications will need to add the following entry into their Gemfile specifying the Uploadcare client library.

gem 'uploadcare-rails', "~> 1.0"

Update application dependencies with bundler.

bundle install

Configuration

Uploadcare requires to store all related config in one single yml file. You should create uploadcare.yml in your config folder. Just run

bundle exec rails g uploadcare_config

then change your API KEYS

# config/uploadcare.yml
defaults: &defaults
  public_key: ENV['UPLOADCARE_PUBLIC_KEY']
  private_key: ENV['UPLOADCARE_SECRET_KEY']

Only two config settings are required: public and private keys. All other posible options are listed here. Config file created by generator also contains a list of all options with default values. Note that global settings are used for internal API calls and as default config for widget. Any instanse of widget can have separate set of config that will override app-wide settings if needed.

Include javascript library in your layout

<%= include_uploadcare_widget_from_cdn %>
<%=
uploadcare_settings %>

Use uploadcare fields

Simple

<%= uploadcare_uploader_field :post, :file %>
<!--
  results in:
  <input id="post_file" name="post[file]" role="uploadcare-uploader" type="hidden">
  <div class="uploadcare-widget" style="display: none;" data-status="ready">
      ....
  </div>
-->

Form tags

<%= form_for(@post) do |f| %>

  <div class="field">
    <%=
f.label :title %><br>
    <%=
f.text_field :title %>
  </div>
  <div class="field">
    <%=
f.label :file %><br>
    <%=
f.uploadcare_field :file %>
  </div>
  <div class="field">
    <%=
f.label :file %><br>
    <%=
f.uploadcare_field :file %>
  </div>
  <div class="field">
    <%=
f.label :image_group %><br>
    <%=
f.uploadcare_multiple_uploader_field :image_group %>
  </div>
  <div class="actions">
    <%=
f.submit %>
  </div>
<%
 end %>

Read more at uploadcare-rails docs

Using with Python/Django

Step 1. Install the pyuploadcare library

pip install pyuploadcare

Step 2. Add authentication settings to your settings.py file

import os

UPLOADCARE = {
    'pub_key': os.environ.get('UPLOADCARE_PUBLIC_KEY'),
    'secret': os.environ.get('UPLOADCARE_SECRET_KEY'),
}

Step 3. Use pyuploadcare.dj.FileField in any model

No arguments needed!

from django.db import models

from pyuploadcare.dj import FileField

class Photo(models.Model):
    title = models.CharField(max_length=255)
    photo = FileField()

Read more in the pyuploadcare docs

Dashboard

callout For more information on the features available within the Uploadcare dashboard please see the docs at Uploadcare site.

The Uploadcare dashboard allows you to manage your projects, files, widget config.

The dashboard can be accessed via the CLI:

heroku addons:open uploadcare
Opening uploadcare for sharp-mountain-4005...

or by visiting the Heroku apps web interface and selecting the application in question. Select Uploadcare from the Add-ons menu.

Removing the add-on

Uploadcare can be removed via the CLI.

warning This will mark your project and all associated data as deprovisioned. Contact us at help@uploadcare.com, to retreive it.

heroku addons:remove uploadcare
-----> Removing uploadcare from sharp-mountain-4005... done, v20 (free)

Support

All Uploadcare support and runtime issues should be submitted via on of the Heroku Support channels. Any non-support related issues or product feedback is welcome at hello@uploadcare.com.

We’re always happy to help with code, integration, and other stuff. Search our site for more info or post your question in our Community Area.