jquery - Pass parameter to WebAPI through Uploadify -


how pass object uploadify webapi controller? not sure how use scriptdata parameter.

i tried this:

    $("#fileinput").uploadify({              'uploader': '/api/files/addfiles/',             'swf'       : '/uploadify/uploadify.swf',             'cancelimage' : '/uploadify/uploadify-cancel.png',             'auto': true,             'folder': "/uploads",             'scriptdata'     : {'product': null }                        });  

here controller:

    public task<httpresponsemessage> addfiles(product product )     {     } 

if remove product parameter controller controller gets called( on clicking "select files") , works fine. when try pass parameter not called. route template is:

  api/{controller}/{action/{id} 

okay. after bit of investigation found uploadify will work happily standard mvc controller action, not appear pass on scriptdata part of request url (according fiddler2).

as alternative can modify formdata setting post additional information:

sample view:

<div class="myuploader">     <input id="file_upload" type="file" name="file_upload" />     <input id="uploadfiles" type="button" value="upload files" /> </div>  <script type="text/javascript">     $(function () {         $('.myuploader').uploadify({             swf: '/content/uploadify.swf',             uploader: 'home/upload',             auto: true,             formdata: {product: 456}             }); 

controller upload action:

    public actionresult upload()     {         httppostedfilebase ofile = request.files["filedata"];         if (ofile != null)         {             string sdirectory = server.mappath("~/files/");             string filename = path.getfilename(ofile.filename);              // can pick parameter set in formdata member of plugin using name             string testparam = request.form["product"];   // gets 456              // file here             return content("1");         }         else         {             return content("0");         }     } } 

follow up:

i still not able uploadify working, @ all, standard webapi controller.

as aside: needed swf , html 5 support have wrapped uploadify , commercial uploadifive in our own plugin, dynamically converts parameters required browser capabilities. have automatically extract hidden field values , combine them formdata. may want try yourself.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -