how to start uploads with a submit button click #279

Open
opened 2016-06-28 15:14:50 +00:00 by sunry81914 · 4 comments
sunry81914 commented 2016-06-28 15:14:50 +00:00 (Migrated from github.com)

how to start uploads file with a submit button click ?

how to start uploads file with a submit button click ?
tylermassey commented 2016-07-12 15:45:38 +00:00 (Migrated from github.com)

If you only want to upload one file, you can create your own upload function and attach it to a click event in your submit button.

In your component HTML file:

<button (click)="upload()">Submit></button>

In your component TS file:

export class YourComponent {
    uploader: FileUploader;

    upload() {
        let file = this.uploader.queue[0];
        file.upload();
    }
}

Hope this helps.

If you only want to upload one file, you can create your own upload function and attach it to a click event in your submit button. In your component HTML file: `<button (click)="upload()">Submit></button>` In your component TS file: ``` export class YourComponent { uploader: FileUploader; upload() { let file = this.uploader.queue[0]; file.upload(); } } ``` Hope this helps.
simoazzo commented 2016-08-10 11:24:53 +00:00 (Migrated from github.com)

Hi @tylermassey

How can I pass parameters to the file upload() method? Because I want to pass a GUID value when triggering my action method in my API controller

Kind Regards

Hi @tylermassey How can I pass parameters to the file upload() method? Because I want to pass a GUID value when triggering my action method in my API controller Kind Regards
tylermassey commented 2016-08-10 15:26:12 +00:00 (Migrated from github.com)

Hi @simoazzo

I believe there is no functionality at this time to post additional data with the file.upload method. This is one limitation of this library. I encountered the same issue because in my application. I needed to upload a file and a form at the same time. I worked around the issue by making my file upload immediately when it is added, and then I created a separate form to post my other data.

If you are trying to only post the uploaded file and a GUID value, you may be able to work around this issue by naming your file with the GUID value and then retrieving this value from the file name on your server.

Good luck!

Hi @simoazzo I believe there is no functionality at this time to post additional data with the `file.upload` method. This is one limitation of this library. I encountered the same issue because in my application. I needed to upload a file and a form at the same time. I worked around the issue by making my file upload immediately when it is added, and then I created a separate form to post my other data. If you are trying to only post the uploaded file and a GUID value, you may be able to work around this issue by naming your file with the GUID value and then retrieving this value from the file name on your server. Good luck!
geejay commented 2016-09-25 21:48:22 +00:00 (Migrated from github.com)

You can set form data by overriding this method:

this.fileUploader.onBuildItemForm = (fileItem, form)

You can set form data by overriding this method: `this.fileUploader.onBuildItemForm = (fileItem, form)`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#279