|
Post by fnllc on Jul 10, 2017 20:57:20 GMT
Using the old Rhomobile API, one could add callback params sing callback_params option:
Rho::AsyncHttp.download_file( :url => file_url, :filename => savefile_name, :headers => {"Content-Type"=>"application/octet-stream"}, :callback => url_for(:action => :download_callback), :callback_param => "filename=#{Rho::RhoSupport.url_encode(file_name)}" )
I have tried the following with new the API, but it does not pass the params:
downloadfileProps = Hash.new downloadfileProps["url"] = file_url downloadfileProps["filename"] = savefile_name Rho::Network.downloadFile(downloadfileProps, url_for(:action => :download_callback, :filename => Rho::RhoSupport.url_encode(file_name) ) )
|
|
|
Post by Vladimir Musulainen on Jul 10, 2017 21:04:52 GMT
Below code snippet from documentationfunction download_file_callback(params) { if (params["status"] == "ok") { alert("Download Succeeded, path is /public/images/sample.png"); } else { alert("Download Failed"); } }
function download_file() { // Download a file to the specified filename. Be careful with the overwriteFile parameter! downloadfileProps = { url: "http://www.google.com/images/icons/product/chrome-48.png", filename: Rho.Application.publicFolder+"/images/sample.png", overwriteFile: true }; Rho.Network.downloadFile(downloadfileProps, download_file_callback); }
|
|
|
Post by fnllc on Jul 10, 2017 22:43:49 GMT
I saw that in the documentation, but this does not show how to pass a custom param to the callback. I need the filename in the callback. It is not available in @params. Maybe I'm not understanding something obvious.
|
|
|
Post by Vladimir Musulainen on Jul 10, 2017 23:48:07 GMT
No way for receiving custom argument to callback. What do you think about using class variable like below?
function download_file_callback(params) { if (params["status"] == "ok") { @@filename #do something here } }
function download_file() { @@filename = '<path-to-file>' Rho.Network.downloadFile({filename: @filename}, download_file_callback); }
|
|