Hi, I have two use cases where I’d like to download files to my game’s folders, which I need to work in iOS, Windows, and Mac. I assume I’ll use the Downloader class? I’m on cocos2d-x 3.16, btw.
In the other use case, I’d need them to give a url to a folder, like drive.google.com/myimages, and I’d like to download all the files found in that folder.
Any thoughts on doing these two? I guess I’d have to do the work in a separate thread, so I can show them the progress and close the dialog after it’s finished (and also to let them stop it), right?
(oh, and a dumb question, I assume I don’t need to prepend http:// or https:// if it’s not there, right?)
Hmmm, I can’t even find the API for network::downloader?
@slackmoehrle, I’m trying the example on that page, and trying to download a file from my google drive, a folder that I shared publicly. However, I get an error:
ERROR downloading, errorCode = -3 (60): Peer certificate cannot be authenticated with given CA certificates
** By the way, I can download the cocos2d-x zip file, so it’s something to do with trying to pull from a shared google drive. Oh, when downloading the cocos2d-x zip file, “expectedTotalBytes” stayed zero the whole time.
You got this error cause https protocol. You can use http link. Or you can look my another example HttpClient/Downloader cancel/abort a request download files by curl. I set CURLOPT_SSL_VERIFYPEER to 0 so this error wont appear. Or you can edit CCDownloader-curl.cpp on cocos/network and set CURLOPT_SSL_VERIFYPEER to 0.
Also, i dunno about google drive but when i downloaded from dropbox i needed set CURLOPT_FOLLOWLOCATION to 1 for handling redirects.
Thanks, I’ll give your alternative a look! I like the Downloader class, but even when I try http, I get the same error. Hopefully, your example will work on Windows, Mac, and iOS, I’ll check it today. And I’ll dabble with Downloader some more.
A friend has suggested I just create a file share on Amazon S3 and host the files there. It does look as a very nice alternative.
With cocos it is not so easy. For some reason on cocos curl has separate headers for each platform at yourproject/cocos2d/external/curl/include/platformdir. And you need add path for each platform depend what IDE you use for build. For example for iOS you need add Header Search Path on Xcode, and for Andoid you need add lines LOCAL_STATIC_LIBRARIES += cocos_curl_static and $(call import-module,curl/prebuilt/android) to Android.mk file.
Dang. Thanks, I’ll need my download functionality to work on iOS, Mac, and Windows. So, there’s no way to get the current cocos2d-x Downloader to work with https? Or is the problem with how convoluted the google drive shared files are named?
I’m sorry to be a pest, and I really appreciate your patience and help. I’ve now set CURLOPT_SSL_VERIFYPEER to 0 and tried, and then set CURLOPT_FOLLOWLOCATION to 1 and tried again, and I’m having no luck.
It’s google drive problem. Try search how download files from gdrive with curl or use another host.
For example https://stackoverflow.com/a/25033499 here is discussion about same problem.
Thanks much, I’ll read that site. I wonder if it would just be better to have people host their files on other sites, like dropbox. I probably should just go with Steam Workshop, but I’ve hesitated, because I have iOS users, too.
Thanks again, maybe that stackoverflow site will help me.