You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
PoulChr
6 years agoHelpful | Level 6
Several xmlhttprequest: very slow
My R-pi based weatherstation collects 48 measurements over an hour. When a new hour starts, these are saved in a file and uploaded to dropbox, - and a new collection begins. When a new day starts...
- 6 years ago
Thanks! I just tried this, and the network requests to the Dropbox links aren't running particularly slowly for me. How are you measuring this? What step exactly is running slow?
I do notice that you have `result` scoped outside any particular function, and you're doing `result+= xhr.responseText`, meaning that each call will yield the concatenation of the results of all previous calls, in addition to the current call. Is that what you intended? The size of that may grow relatively large, especially if the csv files are large to begin with, which could slow down execution. You may want to scope the `result` variable to inside your `onreadystatechange` function, and just pass just the current result to `addTxt`, if that makes sense for what you're building.
Anyway, that aside, I don't see any particular issues with the Dropbox service itself here, but please let me know if I'm missing something.
Also, one other note, you're writing these links to access 'dl.dropbox.com', but that will result in a redirect anyway. If you want to avoid that, you should use 'dl.dropboxusercontent.com' instead. Be aware that accessing file data programmatically via either of these domains isn't officially supported anyway. (You're supposed to use the 'raw=1' parameter, for instance, as documented here, but that may not work for your use case.)
Greg-DB
6 years agoDropbox Staff
I'm not aware of any reason that using XMLHttpRequest in particular should be very slow. Can you share the code you're using and how you're measuring this?
- PoulChr6 years agoHelpful | Level 6
My code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script>
var result;
var files = [ // "dl" and not "www" ! ! !
"https://dl.dropbox.com/s/xyzxyzxyzxyzxyzx/0.csv", …….
, "https://dl.dropbox.com/s/xyzxyzxyzxyzxyzx/23.csv"
];
function readDbox() {
addTxt("Starting download..");
var url;
var xhr = new XMLHttpRequest();
for (let i=0; i<files.length; i++) {
url = files[i];
addTxt(url);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
result+= xhr.responseText;
}
}
xhr.open("GET", url, true); // false => sync
xhr.send();
}
addTxt(result) ;
}
function addTxt(str) { document.getElementById("txtA").innerHTML+= str+"\n"; }
</script>
</head>
<body>
<textarea id="txtA" style="width: 286px; height: 154px" ></textarea><br/><br/>
<input id="btn1" type="button" value="Get file" onclick="readDbox()"/>
</body>
</html>
- Greg-DB6 years agoDropbox Staff
Thanks! I just tried this, and the network requests to the Dropbox links aren't running particularly slowly for me. How are you measuring this? What step exactly is running slow?
I do notice that you have `result` scoped outside any particular function, and you're doing `result+= xhr.responseText`, meaning that each call will yield the concatenation of the results of all previous calls, in addition to the current call. Is that what you intended? The size of that may grow relatively large, especially if the csv files are large to begin with, which could slow down execution. You may want to scope the `result` variable to inside your `onreadystatechange` function, and just pass just the current result to `addTxt`, if that makes sense for what you're building.
Anyway, that aside, I don't see any particular issues with the Dropbox service itself here, but please let me know if I'm missing something.
Also, one other note, you're writing these links to access 'dl.dropbox.com', but that will result in a redirect anyway. If you want to avoid that, you should use 'dl.dropboxusercontent.com' instead. Be aware that accessing file data programmatically via either of these domains isn't officially supported anyway. (You're supposed to use the 'raw=1' parameter, for instance, as documented here, but that may not work for your use case.)
- PoulChr6 years agoHelpful | Level 6
Yes, I really want to put together the contents of all 24 files as they make up a day and night.
I have changed the program a bit, but it still takes 12 seconds to load.
(When I use the method of including 24 javascript files, it takes less than 1 second.
The amount of data is the same.)//-------------------
<!DOCTYPE html ">
<head>
<script>
var files = [
"https://dl.dropboxusercontent.com/s/xyxg0qxyzqwqw2k/0.csv",................
"https://dl.dropboxusercontent.com/s/qwertyytrexyzyxz/23.csv"
];var xhr = new XMLHttpRequest();
var result;function laesDbox(url) {
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) result = xhr.responseText;
}
xhr.open("GET", url, false); // false => sync
xhr.send();
}function getFiles() {
result ="";
addTxt("Get files:");
for (let i=0; i<files.length; i++) {
laesDbox(files[i]);
addTxt(result);
}
}function addTxt(str) { document.getElementById("txtA").innerHTML+= str+"\n"; }
</script></head>
<body>
<textarea id="txtA" style="width: 900px; height:700px"></textarea><br/><br/>
<input id="btn1" type="button" value="Hent fil" onclick="getFiles()"/>
</body></html>
About Discuss Dropbox Developer & API
Make connections with other developers
795 PostsLatest Activity: 11 days agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!