Skip to content

Instantly share code, notes, and snippets.

@brucenorton
Created May 7, 2017 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brucenorton/12cbe0d5f0087a50d66c3dd265ec629f to your computer and use it in GitHub Desktop.
Save brucenorton/12cbe0d5f0087a50d66c3dd265ec629f to your computer and use it in GitHub Desktop.
cloudinary PhotoAlbum dynamic context
$(function () {
"use strict";
//The idea is to only load this once someone has filled out the form
let newContext = 'email=new@test.com|credits=Me New Context';
$('.cloudinary-fileupload')
.cloudinary_fileupload({
dropZone: '#direct_upload',
context: newContext,
start: function () {
$('.status_value').text('Starting direct upload...');
},
progress: function () {
$('.status_value').text('Uploading...');
}
})
.bind('fileuploadprogress', function(e, data) {
$('.progress_bar').css('width', Math.round((data.loaded * 100.0) / data.total) + '%');
})
.on('cloudinarydone', function (e, data) {
$('.status_value').text('Idle');
$.post('upload_complete.php', data.result);
var info = $('<div class="uploaded_info"/>');
$(info).append($('<div class="data"/>').append(prettydump(data.result)));
$(info).append($('<div class="image"/>').append(
$.cloudinary.image(data.result.public_id, {
format: data.result.format, width: 450, height: 450, crop: "fill"
})
));
$('.uploaded_info_holder').append(info);
});
$('.cloudinary-fileupload').cloudinary_fileupload('option', 'formData').context = newContext;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment