javascript - How to append data to dynamic array and use the array in dropbox saver api? -


i created few buttons , onlick of button url , filename send dynamic array , when click dropbox saver button want saver function uses dynamic array send files dropbox. current code gives me error:missing files.see documentation.

its seems didnt save data correctly array , didnt pass correctly saver funciton. 1 me fix problem.thanks

note: want use dynamic array instead of hardcoded url , filenames shown here:

edited: add options.files = files; before calling dropbox.save , declared array outside addtoarray function . error:g undefined @ dropins.js(line 1).

files: [          {'url': '<?php  echo $imagepath1_value; ?>', 'filename': '1.jpg'},         {'url': '<?php  echo $imagepath2_value; ?>', 'filename': '2.jpg'},         {'url': '<?php  echo $imagepath3_value; ?>', 'filename': '3.jpg'},     ], 

dropbox api js:

<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="xxxxxxxxxxxxxx"></script> <script> 

saveing fileurl , filename array function:

 var i=1;   files = new array();        function addtoarray(a,b){     alert("url:"+a+"\nfilename:"+b);      files[i] = { url: +a, filename: +b };     i++;      }; 

dropbox savers function:

function saver(){ var options = {   //here want use array created above instead of hardcode filepath , filenames    //files: [         // can specify 100 files.         // ...         //{'url': '<?php  echo $imagepath1_value; ?>', 'filename': '1.jpg'},         //{'url': '<?php  echo $imagepath2_value; ?>', 'filename': '2.jpg'},         //{'url': '<?php  echo $imagepath3_value; ?>', 'filename': '3.jpg'},     //],      // success called once files have been added user's     // dropbox, although may not have synced user's devices yet.     success: function () {         // indicate user files have been saved.         alert("success! files saved dropbox.");     },      // progress called periodically update application on progress     // of user's downloads. value passed callback float     // between 0 , 1. progress callback guaranteed called @ least     // once value 1.     progress: function (progress) {},      // cancel called if user presses cancel button or closes saver.     cancel: function () {},      // error called in event of unexpected response server     // hosting files, such not being able find file. callback     // called if there error on dropbox or if user on quota.     //error: function (errormessage) {} error:function (errormessage) { alert("error: " + errormessage); } }; options.files = files; dropbox.save(options);  }; </script> 

body of html:

<body> <button onclick="addtoarray('<?php  echo $imagepath1_value; ?>','filename1.jpg')">add array</button>  <button onclick="addtoarray('<?php  echo $imagepath2_value; ?>','filename2.jpg')">add array</button>  <button onclick="saver()">save</button> 

you can build files array want, long options.files array contains necessary information when call dropbox.save. e.g., append shared files variable when call addtoarray (right looks making new 1 each time) , set options.files = files before calling dropbox.save.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -