Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created December 11, 2015 22:55
Show Gist options
  • Select an option

  • Save ORESoftware/c741f752a0e723fb751a to your computer and use it in GitHub Desktop.

Select an option

Save ORESoftware/c741f752a0e723fb751a to your computer and use it in GitHub Desktop.
Cloudinary Gist
/*
Error that I get for both these attempts:
"Missing required parameter - file"
the image is in a base64 string format...
*/
/* Attempt 1: */
$scope.sendToCloudinary = function (img) {
console.log("Sending to Cloudinary...");
var file = img.imageObject.result;
console.log('file before:', file);
file = file.replace("data:image/png;base64,", "");
console.log('file:', file);
var cloud_name = 'hjobxkhvq';
var fd = new FormData();
fd.append('upload_preset', 'seller');
fd.append('file', file, 'douglas.fir');
fd.append('fileName', file);
$http
.post('https://api.cloudinary.com/v1_1/' + cloud_name + '/image/upload', fd, {
headers: {
'Content-Type': undefined,
'X-Requested-With': 'XMLHttpRequest',
'Access-Control-Allow-Credentials': undefined,
'lectal-authorization': undefined
},
data: {
fileName: file,
resource_type: 'image',
format: "jpg",
timestamp: 1375363550
},
withCredentials: false
})
.success(function (cloudinaryResponse) {
// do stuff with cloudinary response
// cloudinaryResponse = { public_id: ..., etc. }
console.log('cloudinary resp:', cloudinaryResponse);
})
.error(function (resp) {
console.log('cloudinary error:', resp);
});
};
/* attempt 2 */
$scope.sendToCloudinary2 = function (img) {
var cloud_name = 'hjobxkhvq';
$http({
method: 'POST',
url: 'https://api.cloudinary.com/v1_1/' + cloud_name + '/image/upload',
data: {
fileName: img.imageObject.result,
resource_type: 'image',
format: "base64",
timestamp: 1375363550,
api_key: '311998699786184'
},
headers: {
'Content-Type': undefined,
'X-Requested-With': 'XMLHttpRequest',
'Access-Control-Allow-Credentials': undefined,
'lectal-authorization':undefined
},
withCredentials: false
}).success(function (data, status, headers, config) {
console.log("success - ",data,status,headers,config);
}).error(function (data, status, headers, config) {
console.log("fail - ",data,status,headers,config);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment