Add a possibility to append other values to FormData object #241
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I would be nice to extend of your sending method about possibility (e.g calling some new method) which would appends other data to created form object
As pointed out by @dmarginian in a duplicate issue (#12), you can already do this. I have verified that it is working in 1.0.3.
this._uploader.onBuildItemForm = (item, form) => {
form.append("key", "value");
};
@msfanous do you have an example of this working? Like with either drag/drop or just a single upload input?
Hi @thehashrocket. Yes, I did get it working with both the single and multiple upload inputs. There wasn't much to it besides adding those extra lines after constructing the uploader. Is there a specific issue that you're seeing?
Here's the file selection component. I chose to use my own button and clear way any old files when a new section is made.
No, that's perfect @msfanous ! Thank you! :)
Is there also a possibility to add your values manually? So not by subscribing to the onBuildItemForm event?
Because I would need to do that after creating the form for each item.
In my case I needed to do an async call before the upload 😢
In the
onAfterAddingFileI add this async information toitem.formDataI then call
item.upload()forcing the upload.Inside the
onBuildItemFormI then form.append the relevant fields.Sadly this forces a type of auto-upload.
so can someone tell me how to access this additional form data on the server side in web api 2?
Hi @msfanous please can you help me out on this same issue. i have tried what you did but i dont seem to get it working. is there anything i am not doing right?
this is my uploader instance
public fileUploader: FileUploader = new FileUploader({});
then i do the next part in the ngonit() method like this
this.fileUploader = new FileUploader({ url: "http://localhost/phat/server/post.php"});
fileItem.withCredentials = false;
return { fileItem, form };
};
Afterwards i proceed to call an upload method where i do the real post of the form like this
upload(){
let files = this.getFiles();
let requests = [];
}
But still it doesnt work... yet the form values are seen in the request body and can be printed on the console.
can anyone help, what am i doing wrong?