Execute a function when select the file #859

Open
opened 2017-08-02 15:44:24 +00:00 by codeboxgt · 4 comments
codeboxgt commented 2017-08-02 15:44:24 +00:00 (Migrated from github.com)

Hi;
I'm a new using your directive, I'm creating a module to upload pictures, but I want execute a function that call a service to upload the picture into the server.

My doubt is very simple, It's possible call a function after select the file?, I mean, when you choose the file in the command dialog and press OK, I want execute a function that get the file and send it to a service, this is possible?

regards.

Hi; I'm a new using your directive, I'm creating a module to upload pictures, but I want execute a function that call a service to upload the picture into the server. My doubt is very simple, It's possible call a function after select the file?, I mean, when you choose the file in the command dialog and press OK, I want execute a function that get the file and send it to a service, this is possible? regards.
CarstenHouweling commented 2017-08-03 11:54:39 +00:00 (Migrated from github.com)

I use ngDoCheck() for file type checking, you can use the same for uploading:

oldQueueLength = 0;

ngDoCheck() {
    // File Upload queue check
    if (this.uploader.queue.length !== this.oldQueueLength) {
      if (this.uploader.queue.length > this.oldQueueLength) {
        // File added
        if (this.uploader.queue[this.uploader.queue.length - 1].file) {
          // Allow only certain file types
          if (this.uploader.queue[this.uploader.queue.length - 1].file.type != 'text/plain' && this.uploader.queue[this.uploader.queue.length - 1].file.type != 'text/xml') {
            this.uploader.queue.splice(this.uploader.queue.length - 1, 1);
          }
        } else {
          this.uploader.queue.splice(this.uploader.queue.length - 1, 1);
        }
      } else {
        // File removed
      }
      this.oldQueueLength = this.uploader.queue.length;
    }
  }
I use ngDoCheck() for file type checking, you can use the same for uploading: ``` oldQueueLength = 0; ngDoCheck() { // File Upload queue check if (this.uploader.queue.length !== this.oldQueueLength) { if (this.uploader.queue.length > this.oldQueueLength) { // File added if (this.uploader.queue[this.uploader.queue.length - 1].file) { // Allow only certain file types if (this.uploader.queue[this.uploader.queue.length - 1].file.type != 'text/plain' && this.uploader.queue[this.uploader.queue.length - 1].file.type != 'text/xml') { this.uploader.queue.splice(this.uploader.queue.length - 1, 1); } } else { this.uploader.queue.splice(this.uploader.queue.length - 1, 1); } } else { // File removed } this.oldQueueLength = this.uploader.queue.length; } } ```
bhaidar commented 2017-08-08 17:34:52 +00:00 (Migrated from github.com)

Hello,
Can you please explain where to call this function? I am also new to this module. Thanks

Hello, Can you please explain where to call this function? I am also new to this module. Thanks
CarstenHouweling commented 2017-08-08 17:52:00 +00:00 (Migrated from github.com)

That's a component lifecycle hook. Google it

That's a component lifecycle hook. Google it
bhaidar commented 2017-08-09 07:08:27 +00:00 (Migrated from github.com)

Thanks I got it :-)

Thanks I got it :-)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#859