-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Support file upload #1236
Comments
Yes, it would be great if it is possible. |
+1 |
+1 this would be helpful |
+1 This would be useful to me as well. |
+1 yes please :D |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Great! Who wants to help write the patch? |
Don't we first need FormData support for $http? |
+1 |
3 similar comments
+1 |
+1 |
+1 |
+1 Would it be a good idea to expose $XHR as a service, instead of XHR being a function scoped variable as it currently is? That way we could add event listeners to the instance. |
+1 thx |
+1 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
👍 |
👍 |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
@paulogaspar - I am sorry that you feel this way. AngularJS is a very pluggable eco-system. Why do you need core to provide this functionality. What is stopping you from using the 3rd party libraries that we have listed already? |
Even egghead.io are taking a while to think about how to tackle this one - https://egghead.uservoice.com/forums/227781-suggestions/suggestions/4860656-how-should-file-uploads-be-implemented-the-angular I wish someone from the AngularJS team would explain how file uploads should be implemented the Angular way - at least in principle. |
@filmaj - why not write your own directive, say |
+1 for $resource (ngResource) |
+1 |
+1 |
@petebacondarwin Because file uploads are pretty common, and it seems reasonable to want to use ngResource whenever possible. |
I made a directive to set into ngModel the base64 string of the file, to send directly to server with the other variables in the rest of the form: 'use strict';
angular.module('app')
.directive('uploadBase64', function (dateFilter) {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
// do nothing if no ng-model
if (!ngModel) {
return;
}
element.on('change', function () {
scope.$apply(function () {
var files = element[0].files,
encoded_data = [];
angular.forEach(files, function (file, i) {
var reader = new FileReader();
reader.onload = function (e) {
encoded_data.push({
name: file.name,
size: file.size,
type: file.type,
data: e.target.result
});
if (i === (files.length -1)) {
ngModel.$setViewValue(encoded_data);
}
};
reader.readAsDataURL(file);
}, this);
});
});
}
};
}); |
@marcalj, the main problem of FileReader is: https://developer.mozilla.org/en-US/docs/Web/API/FileReader#Browser_compatibility Take a look here: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills#file-api However, angular needs to offer this functionality by default like a module with great compatibility. |
Yep, in my case my minimum version of IE is v10 :) |
@petebacondarwin referring to your comment It would be much easier to implement progress and cancel/abort functionality for https://github.com/danialfarid/angular-file-upload plugin if this issue is resolved. |
As mentioned by @caitp this PR or some form of it will make it into 1.3. See #1934 (comment) |
You can also see my upload module and this. Features of my module:
|
+1 |
3 similar comments
+1 |
+1 |
+1 |
+1 Huge pain dealing with type="file" right now. |
+1 |
Definetely agree. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
In 1.5.5 you can react to any of the XHR events in |
Locking to prevent the the proliferation of +1s |
Right now, we have to write our own directives to make angular upload files using html5's xhr. It would be nice if angular could do that automatically when there's a file input in a form.
The text was updated successfully, but these errors were encountered: