简体   繁体   中英

Sending form data with angular-file-upload

I'm using nervgh's angular-file-upload and I'd like to send formData based on user inputs. I can request different fields from the formData but not when they are pushed onBeforeUploadItem.

I have the uploader set up like so:

var uploader = $scope.uploader = new FileUploader({
        url: 'upload.php',
        formData: [{
         param1: 'value1',
         param2: 'value2',
         param3: 'value3'
       }]            
    });

uploader.onBeforeUploadItem = function(item) {
        item.formData.push({test: 'TEST'});
        console.info('onBeforeUploadItem', item);
    };

In my upload.php I get value1 for $_REQUEST['param1'] but I get no data when I do the same with test, $_REQUEST['test'].

$myValue1 = $_REQUEST['param1']; <-- equals value1
$test = $_REQUEST['test']; <-- empty

Any idea how I can get an added field from my upload.php? Thanks

Instead of trying this way, you may try to upload your files via formData using multipart/form-data . An example is given below:

    <form action="yoururl" method="post" ng-submit="yoursubmitaction" enctype="multipart/form-data">
       <input type="text" name="text1" />
       <input type="text" name="text2" />
       <input type="file" name="Attachment"/>
    </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM