Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Support file upload #1236

Closed
patcito opened this issue Aug 7, 2012 · 117 comments
Closed

Support file upload #1236

patcito opened this issue Aug 7, 2012 · 117 comments

Comments

@patcito
Copy link

patcito commented Aug 7, 2012

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.

@pavlovt
Copy link

pavlovt commented Aug 7, 2012

Yes, it would be great if it is possible.

@javierpavon2000
Copy link

+1

@ialtamirano
Copy link

+1 this would be helpful

@kamui
Copy link

kamui commented Aug 7, 2012

+1 This would be useful to me as well.

@wintery
Copy link

wintery commented Aug 7, 2012

+1 yes please :D

@dylanz
Copy link

dylanz commented Aug 13, 2012

+1

3 similar comments
@alexeygolev
Copy link

+1

@TomiMikola
Copy link

+1

@jmparraguez-haulmer
Copy link

+1

@nateabele
Copy link

Great! Who wants to help write the patch?

@celmaun
Copy link

celmaun commented Sep 16, 2012

Don't we first need FormData support for $http?

@vlamic
Copy link

vlamic commented Sep 17, 2012

+1

3 similar comments
@arselvam
Copy link

+1

@hparra
Copy link

hparra commented Nov 18, 2012

+1

@ghost
Copy link

ghost commented Nov 28, 2012

+1

@jgrund
Copy link
Contributor

jgrund commented Nov 29, 2012

+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.

@jurby
Copy link

jurby commented Dec 5, 2012

+1 thx

@esteveavi
Copy link

+1

6 similar comments
@aozora
Copy link

aozora commented Dec 20, 2012

+1

@rsijaya
Copy link

rsijaya commented Jan 2, 2013

+1

@ajeliuc
Copy link

ajeliuc commented Jan 3, 2013

+1

@amelekesov
Copy link

+1

@michaelcpuckett
Copy link

+1

@cosenal
Copy link

cosenal commented Jan 27, 2013

👍

@BernhardPosselt
Copy link

👍
I really need fileupload via formdata

@sabbaticaldev
Copy link

+1

4 similar comments
@evrijkom
Copy link

+1

@Dolmio
Copy link

Dolmio commented Feb 12, 2013

+1

@jaisonjustus
Copy link

+1

@zhex
Copy link

zhex commented Feb 15, 2013

+1

@petebacondarwin
Copy link
Contributor

@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?

@jhngrant
Copy link

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.

@petebacondarwin
Copy link
Contributor

@filmaj - why not write your own directive, say fm-file-change, which will do this for your particular application?

@bettysteger
Copy link

+1 for $resource (ngResource)

@badtwin
Copy link

badtwin commented Dec 19, 2013

+1

@CWSpear
Copy link
Contributor

CWSpear commented Dec 28, 2013

+1

@paulogaspar
Copy link

@petebacondarwin Because file uploads are pretty common, and it seems reasonable to want to use ngResource whenever possible.

@marcalj
Copy link

marcalj commented Jan 19, 2014

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);
                    });
                });
            }
        };
    });

@candreoliveira
Copy link

@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.

@marcalj
Copy link

marcalj commented Jan 19, 2014

Yep, in my case my minimum version of IE is v10 :)

@danialfarid
Copy link

@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.

@petebacondarwin
Copy link
Contributor

As mentioned by @caitp this PR or some form of it will make it into 1.3. See #1934 (comment)

@nervgh
Copy link

nervgh commented Jan 20, 2014

You can also see my upload module and this.

Features of my module:

  • HTML5 (formData) + Iframe upload
  • the uploading queue
  • drag-n-drop and <input type="file" />
  • upload progress (for single file and the queue)
  • filtering before adding to queue
  • canceling of uploading (for single file and the queue)
  • creating thumbnails on canvas for images (optional)
  • write less do more =)
  • ...

@kuraga
Copy link

kuraga commented Sep 4, 2014

+1

3 similar comments
@isidroamv
Copy link

+1

@chris31389
Copy link

+1

@josh256
Copy link

josh256 commented Dec 1, 2014

+1

@demisx
Copy link

demisx commented Feb 19, 2015

+1 Huge pain dealing with type="file" right now.

@lareb
Copy link

lareb commented Apr 21, 2015

+1

@hledo
Copy link

hledo commented Jun 24, 2015

Definetely agree.

@lrettig
Copy link

lrettig commented Aug 31, 2015

+1

3 similar comments
@schokshi
Copy link

schokshi commented Sep 2, 2015

+1

@fnagel
Copy link

fnagel commented Feb 28, 2016

+1

@mohamedhafezqo
Copy link

+1

@petebacondarwin
Copy link
Contributor

In 1.5.5 you can react to any of the XHR events in $http, which provides the basic core feature that you can use with $http to do your own file upload work. We are not going to implement anything more specific to support file uploads at this time.

@angular angular locked and limited conversation to collaborators Apr 16, 2016
@petebacondarwin
Copy link
Contributor

Locking to prevent the the proliferation of +1s

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests