Last active
December 11, 2015 22:29
-
-
Save valyagolev/4669980 to your computer and use it in GitHub Desktop.
Demonstrative code snippets for Uploadcare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- The best place for these is your <HEAD> tag --> | |
<script async="async" | |
src="https://ucarecdn.com/widget/0.6.0/uploadcare/uploadcare-0.6.0.min.js"> | |
</script> | |
<script>UPLOADCARE_PUBLIC_KEY = "demopublickey";</script> | |
<!-- This is where the widget will be. Don't forget the name attribute! --> | |
<input type="hidden" role="uploadcare-uploader" name="my_file" /> | |
<!-- That's all! --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Store it: | |
$api = new Uploadcare\Api("demopublickey", "demoprivatekey"); | |
// or Uploadcare_Api for old PHPs | |
$file = $api->getFile($_POST['my_file']); | |
$file->store(); | |
?> | |
<!-- Show it, cropped as needed: --> | |
<img src="<?= $file->scaleCrop(200, 200, 'center')->effect('flip')->getUrl(); ?>"> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cURL Friendly | |
# Upload without a secret | |
$ curl -X POST https://upload.uploadcare.com/base/ \ | |
-F '[email protected]' \ | |
-F 'UPLOADCARE_PUB_KEY=demopublickey' | |
{"example": "c7030ce8-762a-4bee-aed4-acf244fbc8a5"} | |
# Store by id | |
$ curl -X PUT https://api.uploadcare.com/files/c7030ce8-762a-4bee-aed4-acf244fbc8a5/storage/ \ | |
-H 'Authorization: Uploadcare.Simple demopublickey:demoprivatekey' | |
{"original_file_url": | |
"https://ucarecdn.com/c7030ce8-762a-4bee-aed4-acf244fbc8a5/example.jpg", | |
[...]} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Integration with Django Models | |
# without boring configuration | |
from django.db import models | |
from pyuploadcare.dj import FileField | |
class Photo(models.Model): | |
title = models.CharField(max_length=255) | |
photo = FileField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Client client = new Client("demopublickey", "demoprivatekey"); | |
Account account = client.getAccount(); | |
List<URI> published = new ArrayList<URI>(); | |
List<File> files = client.getFiles(); | |
for (File file : files) { | |
if (file.isMadePublic()) { | |
published.add(file.getOriginalFileUrl()); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// and for iOS! | |
UPCUploadController *uploadcare = | |
[[UPCUploadController alloc]initWithUploadcarePublicKey:@"demopublickey"]; | |
[self presentViewController:uploadcare animated:YES completion:nil]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WIP subject to change :/ | |
$(function() { | |
var myButton = $('#some-button'); | |
var uploader = new uploadcare.uploader.Uploader(); | |
// Use any element to show a circle with upload progress, | |
// if you like it! | |
var circle = new uploadcare.ui.progress.Circle('#circle'); | |
myButton.click(function() { | |
// Friendly API based on $.Deffereds: | |
uploadcare.widget.showDialog().pipe(function(file) { | |
var upload = uploader.upload(file); | |
circle.listen(upload); | |
return upload; | |
}).fail(function(error){ | |
alert(['error', error]) | |
}).done(function(file) { | |
alert(['file', JSON.stringify(file)]); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In a Model | |
class Post < ActiveRecord::Base | |
attr_accessible :content, :name, :title, :file | |
is_uploadcare_file :file | |
end | |
# In a View | |
<%= f.uploadcare_uploader_field :file %> | |
<%= image_tag @post.file.public_url("scale_crop/300x200", | |
"effect/grayscale") %> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WIP, subject to change | |
> {-# LANGUAGE OverloadedStrings #-} | |
> import Web.Uploadcare | |
> main :: IO () | |
> main = do | |
> client <- newDemoClient | |
> efile <- getFile client "1d4d470b-8048-4c00-8ae6-9be332e7d2b1" | |
> putStrLn $ case efile of | |
> Right file -> originalFileUrl file | |
> Left err -> err |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment