Start a new topic

File upload in angular to kinvey collection

Hi,

I am working on getting images uploaded to an existing kinvey collection but am having a ton of trouble getting kinvey to play nice with ng-file-upload.

ng-file-upload uses this:



html:









JS:

angular.module('myApp', ['angularFileUpload']);



var MyCtrl = [ '$scope', '$upload', function($scope, $upload) {

$scope.onFileSelect = function($files) {

//$files: an array of files selected, each file has name, size, and type.

for (var i = 0; i
var $file = $files[i];

$upload.upload({

url: 'my/upload/url',

file: $file,

progress: function(e){}

}).then(function(data, status, headers, config) {

// file is uploaded successfully

console.log(data);

});

}

}

}];



and I am struggling with getting the kinvey upload to work with it. I have it working for a php server but that doesn't help me. Can someone show me how to implement kinvey in this?

thanks.

so far this is what i have:



var promise = $kinvey.File.upload(files[0].file,{

_filename: files[0].file.name,

public: true,

size: files[0].file.size,

mimeType: files[0].file.type

}).then(function (_result) {

console.log("$upload: " + JSON.stringify(_result));

//file.cancel()

}, function error(err) {

console.log('[$upload] received error: ' + JSON.stringify(err));

});



return promise;



});
Are you getting either of the console.logs in your second post example? If not, can you try adding another error callback to the returned promise?



A working example on something like jsfiddle.net for the AngularJS bit would be helpful, or at least something more complete posted here that shows your AngularJS code together with Kinvey code?
http://jsfiddle.net/p37bn/9/

for how I currently have it set up to save the url to the kinvey collection because I cant figure out image uploads.



Instead of a text input box I want to be able to select an image to upload.
I’ve created a small snippet [here](https://gist.github.com/vseventer/3835e6cfc5353259afe8). It uploads an image successfully. Please make sure you use the [File Upload plugin](https://github.com/danialfarid/angular-file-upload).
Login or Signup to post a comment