In my Angular application, I have created a resource named 'Files' with the following definition:
app.factory('Files', function($resource) {
return $resource('/api/accounts/:account_id/sites/:site_id/files/:file_id');
});
If I want to create a new file, I use the following syntax:
var file = new Files($scope.file);
file.$save( $stateParams );
Now, I am wondering how I can retrieve the URL that is used by file.$save (POST /api/accounts/:account_id/sites/:site_id/files) in my controller, where all $stateParams parameters are already filled in.
UPDATE:
I am currently working on uploading a file using ng-file-upload. This module requires the URL to be specified when calling the upload function:
$scope.upload = function (file) {
var url = 'api/accounts/' + $stateParams.account_id + '/sites/' + $stateParams.site_id + '/files';
Upload.upload({
url: url,
data: {file: file}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
getFiles();
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
I am trying to find a way to avoid manually constructing the URL variable. After looking at the angular $resource source code, it seems this might not be possible. Is there a workaround for this?