About Headers.token interception issues with Webuploader upload file plugin

Source: Internet
Author: User

Webuploader Event Description
uploadBeforeSend
  • object{Object}
  • data{Object}

    The default upload parameters, which can be extended to control the upload parameters.

  • headers{Object}

    You can extend this object to control the upload header.

When a chunk of a file is triggered before it is sent, it is used primarily to ask whether to add an accompanying parameter, and this event may be triggered multiple times when a large file is opened with a multipart upload.

"Webuploader API documentation "

Add an interceptor to the ANGULARJS, for example:

//Add a Submit tokenSxapp.factory (' Sessioninjector ',function($rootScope, locals) {//Service Logic$rootscope.sysuser.token    varSessioninjector ={request:function(config) { config.headers.token = Locals.getobject ("Accesstoken"); if(config.method== "POST"){                ... ...            }            returnconfig;    }    }; returnsessioninjector;});

Here the headers.token to Webuploader plug-ins do not work, then you need to configure the header in Webuploader, find the webuploader.js in the Uploadbeforesend method, in the header defined in the upload operation method _dosend , add headers.token = Globalconfig.token; This line of code

             /** * @event Uploadbeforesend * @param {Object} Object * @param {object} data default upload parameter             , you can extend this object to control the upload parameters.             * @param {Object} headers can extend this object to control the upload header.             * @description when a chunk of a file is triggered before it is sent, it is primarily used to ask if it is possible to add an accompanying parameter, and this event may trigger multiple times when a large file is opened with a multipart upload. * @for Uploader*/            //do the upload operation. _dosend:function(block) {varme = This, owner=Me.owner, opts=me.options, File=Block.file, tr=NewTransport (opts), data=$.extend ({}, Opts.formdata), headers=$.extend ({}, opts.headers), requestaccept, ret; Headers.token = Globalconfig.token; Block.transport=TR; Tr.on (' Destroy ',function() {                    DeleteBlock.transport;                    Me._popblock (block);                Base.nexttick (Me.__tick); });

Note: Since Angularjs and jquery are cumbersome to pass values, a global variable globalconfig.tokenis declared here, passing values between Angularjs and jquery.

Declare a global variable in config.js:

function GlobalConfig () {}globalconfig.token= "";(function() {}) ();

To pass the value in App.js:

Globalconfig.token = Locals.getobject ("Accesstoken");

About Headers.token interception issues with Webuploader upload file plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.