valor-software / ng2-file-upload

Easy to use Angular components for files upload
http://valor-software.github.io/ng2-file-upload/
MIT License
1.91k stars 662 forks source link

Submitting form with or without file selected #894

Open ghost opened 6 years ago

ghost commented 6 years ago

Please i am finding it difficult to post my form without me selecting a file. I want the form submitted with or without a file selected. Please I need this ASAP. Thanks in advance.

adrianfaciu commented 6 years ago

Provide a simple repository reproducing this problem and what issue you have with using this component. We can't help you without info about the problem. Also if you don't have a bug/issue for ng2-file-upload you have better chances to get a response if you ask on StackOverflow.

AckerApple commented 6 years ago

(comment UPDATE): I pasted to the wrong issue report. Please ignore. The reporter of this issue is not giving any details and I certainly dont want to encourage him to report issues on my fork

ORIGINAL COMMENT

I have finished addressing this in v0.2.0 of angular-file

Recommend moving to my fork for the requested functionality

pzontrop commented 6 years ago

I think i know what he means because I have the same issue. I am adding form data to the FileUploader by using onBuildItemForm and everything works just fine as long as the user has added at least 1 file to the form.

this.fileUploader.onBuildItemForm = (item, form) => {
            form.append('fieldName', this.formField.value);
};
    submitForm() {
        this.fileUploader.uploadAll();
    }

However I would like it if FileUploader.uploadAll() would trigger a post of the form data even when the file queue is empty.

Temporarily solved it by adding a dummy file to the queue when empty but that's just a very ugly workaround which triggers extra work for the backend (removing the dummy file again).

if(this.fileUploader.queue.length === 0) {
            this.fileUploader.addToQueue([new File([new Blob([""])], "dummy")]);
        }
        this.fileUploader.uploadAll();
agarwal57 commented 6 years ago

Am also facing the same issue reported by pzontrop. i.e., how to use the ng2-file-upload to submit the form data, even when the file is optional

joecutter commented 6 years ago

@pzontrop could you give a simple example am stack on this. I have a form and i want to submit all the data at once with the image uploaded!

Will appreciate alot..!

bot101 commented 6 years ago

@AckerApple if you want people to use your package, the links you add should point to the package's github repo and not npm. I have clicked two links you posted, and both of them point to npm instead of github. I should be able to learn more about what I'm about to use before doing so.

AckerApple commented 6 years ago

@bot101, I couldn't disagree more. NPM is the distribution channel of choice. Anyone using NodeJs knows if its on npm that they can just run npm install angular-file. With what you are asking, they have to run npm install github:ackerapple/angular-file or know an npm package exists. I trust packages on npm more than on github. Github is like the open hole of any coder, I find coders with packages on npm to often be more refined and more professional code (not always).

Do you have any packages on npm? Bro, do you even NPM? I would assume you do. I mean the github repository link is on the damn NPM page.

I see it different than you. I also have a real icon and a real name so what you hiding from. You know it all though.

dangquang1020 commented 6 years ago

@AckerApple I think it can be easier to use with json data instead of ngfFormData directive. Inside the package you can convert json data to form data just like ng2-file-upload.

AckerApple commented 6 years ago

@dangquang1020

Ummmmmmm absolutely no, that’s incorrect

When selecting files in HTML, the BINARY data in memory is represented as an HTML5 File type object which is transmittable via the HTML5 FormData type object.

You recommend sending json..... Ummmmm binary and json don’t mix..... You thinking this through? Even this package we are making comments on, creates a FormData object to transmit files as seen here.

Try again? I could be wrong but I just say that to come off less aggressive (which saying so does the opposite even more).

Lol, be good

ganqqwerty commented 6 years ago

What I do now is I separate the file upload process from the form submit/save draft process.

AckerApple commented 6 years ago

I built angular-file for only selecting files. Angular4 to Angular5 switched Http classes and Http2 is said to be coming along, it's too much for a file selecting package to keep up with.

It is always best for long term, that functionality be limited to single duties and this applies even to packages (upload separated from selecting files).

All the money to all of you. We all win with open source.

bot101 commented 6 years ago

@AckerApple all the other projects deployed on NPM and have a github repo LINK YOU TO THE REPOSITORY TO LEARN WHAT THE PROJECT IS ABOUT, A WELL AS HOW TO USE IT. You can't recommend your fork and point me to NPM when I am supposed to know if the project is best suited for my needs, as well as what quirks I should know about before using the project. I and many others don't just blindly install libraries without knowing if it's best suited for what it's needed for. Before I could determine if this was what I needed or not, I had already visited your NPM repo 3 times from links that suggested I might find some information regarding the functionality which I needed that was not available in the original repo.

As for my choice of icon and username, my choice, my style, that's all I can say to you. Also, I don't need to have a package on NPM to be validated. As we say in the part of the world I come from, "who NPM package epp?" Go figure.

AckerApple commented 6 years ago

You know it all opinionated dick head.

Go fork yourself.

AckerApple commented 6 years ago

If you have such big issues with how I link shit, I have to imagine your world sucks hard.

Those who have judgements must live up to their own judgements. I’d hate to be you trying to live up to your own shitty skyscraper high expectations.