I have this code (in a service) based on restangular (it works):
sendFile: function (params) {
console.log('sendFile');
console.log(params);
return this.restfulBase().post('file.json',params,{},{ 'X-CSRF-Token' : ipCookie('csrftoken')});
}
How can I, in my controller/directive, get the progress of this upload only with use of Restangular ? I have read that I can write my upload function that use directly XHR or a jQuery plugin like FileUpload, but i want to use only restangular so that my user don't load useless js files.
Or is there a possibility to intercept when upload start ? In this way I can write a div "Loading..." (ok, it is not good like a progress bar, is better than nothing).
Thanks.
As far as I know, there is no way to track the progress of a RESTful request, like you would with a normal file upload.
I've been trying to find the exact same thing for a couple weeks now, but to no avail.
Following what the previous answers mention, the only states you can really track are:
And if you'd like, the time it takes for the request to complete. Hope this helps :)
You can do that using HTTP Interceptors. This will be just few lines of code in your app which works well with Restangular. Using this you can determine when a request started and response is received. Also check how many pending request exist. Below is the sample code that might help. Read more about HTTP Interceptors in Angular.
{
}
Later in your controller/service you can check if
The above code have syntax errors. But that's how it works. You will get many examples about HTTP Interceptor.
Hope that helps :)
Here is my solution to create a Restangular animationd during api requests.
First add a response interceptor and a request interceptor that sends out a rootscope broadcast. Then create a directive to listen for that response and request.:
Here is the directive: