Dropbox dead links - but a alternative isn't working?

Get help using Construct 2

Post » Sun Mar 19, 2017 4:19 am

Hi guys!
Up until last wednesday i was able to use my code without any issues whatsoever.
Now the files i was requesting turn out empty in my project. I checked the Dropbox URL and it is dead (as Dropbox dropped that direct access functionality recently).

However, even after uploading this file to an FTP server I'm still not being able to read the file. I read something about MIME types conflicting with AJAX being able to read files?

In other words:
This no longer works: Image
This does not work: Image

You can try and access that last one yourself... you'll see a list of usernames but AJAX can't seem to fetch them.

No other changes were made to the code whatsoever.


Someone please help!
All of my projects revolve around files and are no longer working since dropbox changed their ways - even though I can access them via an alternative method.

Thanks for the tips in advance!
B
12
S
3
Posts: 51
Reputation: 1,278

Post » Sun Mar 19, 2017 4:35 am

I think the server the file is on needs to allow an Ajax request or I think the wording is cross domain requests. Typically I just put files in the files folder of the project and not worry about it. You should also be able to upload the file the same place you uploaded your html export to. Although I guess you're using some other kind of export.

I think there is an "on error" condition in the Ajax object that could be used to probably get an error message. You could also see if there's any settings you can set for the server you uploaded to? My guess is unless it's your own server you won't have control over that. Or maybe just try uploading somewhere else?
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Sun Mar 19, 2017 4:47 am

R0J0hound you're being extremely helpful as usual and you saved me several times now - so I really appreciate your reply!

I believe you may be right.. I also read this article on Making AJAX requests cross-domain which I'm not sure if it may be causing issues.

Update: got this error which definitely confirms it: Image

I have one question though when using your method: I tried adding the file to my .capx folder and called it like this:
Image
or like this:
Image

None of those methods worked at all... am I doing something wrong when loading a local file?
I was in preview and using a local .capx file/folder.
B
12
S
3
Posts: 51
Reputation: 1,278

Post » Sun Mar 19, 2017 5:04 am

If you added the files from inside c2 the second should work. There's also the "request project file" action.
I said "from inside c2" because I'm not sure just adding the the files in your project folder from Windows explorer is enough. I think there's an xml file the c2 uses to list the files, but c2 takes care of that when adding the files from the editor. If you are using the editor to add the files then disregard.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Sun Mar 19, 2017 6:44 am

R0J0hound wrote:If you added the files from inside c2 the second should work.


I was a bit confused by your reply. I can't seem to be able to add a file to the project... I suppose this could possibly be done using XML but to be honest i have no idea how to do that or if there's an easier approach.

Instead I opted for the FileChooser object and then I asked AJAX to fetch the FileChooser's picked file's URL.
However, this forces me to pick a file every single time I want to use my app since it does not allow for a default file to be picked at the start of the layout.
This does work well.. but it is not viable for me to have to have to pick the same file every time just to get a proper URL to the file (a URL that works -> since I can't get my previous examples to work!).

I noticed that the FileChooser's URL value is something like "Blob:http://localhost:50000/3e94a87df-6532-4413-n187-996830dnb630f" and it keeps changing every time I load the file manually.

This is what I've got right now:
Image

->Can there be a static URL to this local file?
->And how would you load it from inside Construct?

Thanks!
B
12
S
3
Posts: 51
Reputation: 1,278

Post » Sun Mar 19, 2017 7:06 am

I probably rambled too much. Maybe this is helpful?
https://www.scirra.com/manual/141/files
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Sun Mar 19, 2017 7:20 am

R0J0hound wrote:I probably rambled too much. Maybe this is helpful?
https://www.scirra.com/manual/141/files


Oh thank you, I was right-clicking the wrong folder!

However, this does not seem to help in my particular case as my intention is to read a .txt file every x seconds because that file keeps changing over time by using another piece of software. When I import it to Construct it becomes a static file inside the .capx that can't be edited by external applications...

Any other ideas on how to access an external local file? :(

~
Thank you for your help!
B
12
S
3
Posts: 51
Reputation: 1,278

Post » Sun Mar 19, 2017 8:32 am

There in lays the problem with any game that relies on outside files to run.

The cloud is notorious for moving files to make space which changes the file pointers.

People getting C3 that relies heavily on cloud storage are going to find that out the hard way I think.
Banned User
B
28
S
7
G
58
Posts: 1,229
Reputation: 34,830

Post » Sun Mar 19, 2017 9:38 am

If you use the nwjs export/preview you can use the readfile expression of the nwjs object to read a local file.

For a normal HTML preview the browser should prevent access to local files. If you export as html you should be able to access files in that same folder if you just use "nomes.txt".
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Mon Mar 20, 2017 12:59 am

R0J0hound wrote:If you use the nwjs export/preview you can use the readfile expression of the nwjs object to read a local file.


I believe you are right... the nwjs readfile expression really does work very well and just enough for my requirements (I can even link my local dropbox file path or to a file in the app's folder). Performance is great and the code is simpler than using AJAX functions. Only downsize is not being able to experiment with it in Preview mode - having to export every time - but for that i can instead use the previous Filechooser method I referred.

For future reference to other people: the nwjs readfile retrieves the contents of the file by inputting its path.
I'm saving these contents as a string. NWjs.AppFolder refers to the exported App's path, but you may instead type the full path in " " including the filename:
Image

For further info please refer to this document: Exporting desktop apps with NW.js.

R0j0hound you've been awesome for helping me out again! Thank you so much!
B
12
S
3
Posts: 51
Reputation: 1,278

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests