2

I would like to pass a token field and its value along with file upload action. I'm using the Bootstrap file input plugin , But it not sending the custom headers into the nodejs server like the other default header. I have tried the code below. please help me to fix this issue.

This code working fine with my local apache server with php based code, This issue showing only in my nodejs server and i'm using sailsjs.

<!DOCTYPE html>
<html  lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.3.1/css/fileinput.css" rel="stylesheet" type="text/css"><br>
        <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.3.1/js/fileinput.min.js"></script>
        <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<input id="file-1" class="file" type="file" multiple data-preview-file-type="any">
<script>
    $("#file-1").fileinput({
        uploadUrl: '#', // you must set a valid URL here else you will get an error
        allowedFileExtensions : ['jpg', 'png','gif'],
        overwriteInitial: false,
        maxFileSize: 1000,
        maxFilesNum: 10,
        ajaxSettings: { headers: { 'Token': 'XXX55' } },
    });
</script>
</body>
</html>
sijo vijayan
  • 1,590
  • 1
  • 21
  • 34
  • I have tried your code and see header Token XXX55 in FireBug. May be problem is server side? – Kostya Shkryob Apr 15 '16 at 15:08
  • @KostyaShkryob You are correct, I have just tried this code with a apache server with php and now it works fine. but my production server is Node Server. Thanks for your suggestion – sijo vijayan Apr 15 '16 at 15:46
  • So may you please provide server side code? Getting headers in SailsJS looks pretty straightforward (http://sailsjs.org/documentation/reference/request-req/req-headers). – Kostya Shkryob Apr 15 '16 at 19:57

0 Answers0