gpt4 book ai didi

javascript - 如何将数据附加到动态数组并在 dropbox saver api 中使用该数组?

转载 作者:行者123 更新时间:2023-12-02 16:05:47 26 4
gpt4 key购买 nike

我创建了一些按钮,并且单击按钮 url 和文件名发送到动态数组,当我单击 dropbox saver 按钮时,我希望 saver 函数使用该动态数组将文件发送到 dropbox。我当前的代码出现此错误:缺少文件。请参阅文档。

看来我没有将数据正确保存到数组中,也没有正确地将其传递给保存程序函数。谁能帮我解决这个问题。谢谢

注意:我只想使用动态数组而不是硬编码的网址和文件名,如下所示:

编辑:我添加 options.files = files;在调用 dropbox.save 并在 addtoarray 函数之外声明我的数组之前。现在我收到此错误:G 在 dropins.js(第 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>

将文件网址和文件名保存到数组函数:

 var i=1;
files = new Array();
function addtoArray(a,b){
alert("URL:"+a+"\nFileName:"+b);

files[i] = { url: +a, filename: +b };
i++;

};

Dropbox 保存功能:

function saver(){
var options = {

//here i want to use array i created above instead of hardcode filepath and filenames



//files: [
// You can specify up to 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 is called once all files have been successfully added to the user's
// Dropbox, although they may not have synced to the user's devices yet.
success: function () {
// Indicate to the user that the files have been saved.
alert("Success! Files saved to your Dropbox.");
},

// Progress is called periodically to update the application on the progress
// of the user's downloads. The value passed to this callback is a float
// between 0 and 1. The progress callback is guaranteed to be called at least
// once with the value 1.
progress: function (progress) {},

// Cancel is called if the user presses the Cancel button or closes the Saver.
cancel: function () {},

// Error is called in the event of an unexpected response from the server
// hosting the files, such as not being able to find a file. This callback is
// also called if there is an error on Dropbox or if the user is over quota.
//error: function (errorMessage) {}
error:function (errorMessage) { alert("ERROR: " + errorMessage); }
};
options.files = files;
Dropbox.save(options);

};
</script>

html 正文:

<body>
<button onclick="addtoArray('<?PHP echo $imagePath1_Value; ?>','filename1.jpg')">add to array</button>

<button onclick="addtoArray('<?PHP echo $imagePath2_Value; ?>','filename2.jpg')">add to array</button>

<button onclick="saver()">save</button>

最佳答案

您可以根据需要构建 files 数组,只要 options.files 数组在调用 Dropbox.save 时包含必要的信息即可>。例如,当您调用 addtoArray 时,附加到共享的 files 变量(现在看起来您每次都在创建一个新变量),然后设置 options.files = 在调用 Dropbox.save 之前的文件

关于javascript - 如何将数据附加到动态数组并在 dropbox saver api 中使用该数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30763317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com