nervgh / angular-file-upload

[ALMOST NOT MAINTAINED] Angular File Upload is a module for the AngularJS framework
MIT License
3.43k stars 1.13k forks source link

Upload extra data with file #771

Open meoz opened 7 years ago

meoz commented 7 years ago

I'm using Angularjs to C# MVC to upload a file to the server. Works great, only sending extra parameters with file does not seem to work. I've tried all kind of things but can't get it to work.

on the client I'm doing this for each file in the queue:

     function uploadItem (fileItem) {
            fileItem.url = 'server/Upload';
            fileItem.formData.push({ id: 'test' });
            fileItem.upload();
        }

on ther server I'm doing this (.net):

        [HttpPost]
        public ActionResult Upload(HttpPostedFileBase file)
        {
           //no idea how to get formData parameters ?
          //...

          ProcessFile(file);

            return Json(restultText, JsonRequestBehavior.AllowGet);
        }

Any idea how I could get this to work ?

iit2011081 commented 7 years ago

You can pass extra params like this

var uploader = $scope.uploader = new FileUploader({
        url: '/upload.php',
        formData: [ { "key1": "value1" },{ "key2": "value2" }],
 });