Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Phonegap FileDownload ... passing array of filenames from xbasic to javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Phonegap FileDownload ... passing array of filenames from xbasic to javascript

    Hi, I'm trying to implement the example of downloading files from a server using PhonegapFiledownload, and first parameter can be an array of file names.

    Basically, the instructions say: Specify the name of a Javascript function to call. this function must return an array containing the names of files that you want to download. You can specify fully qualified files or relative files (paraphrasing the last sentence).

    The steps are:

    1. Do ajax callback to get a list of urls and put them into {dialog.object}._urlToFetch. Here is the relevant parts to the callback:

    Code:
    'get the URL for this session file
    dim url as c 
    url = Session.FormatFileDataURL(clientSideFileName)
    
    
    'construct the Javascript response that will be sent to the client
    'note that we specify that a function called 'fetchFile()' should be called
    'on the client-side with the name of the URL that points to the temporary
    'file in session storage. This 'fetchFile()' function is a user-defined
    'Javascript function that you will need to add to your UX component
    
    dim js as c 
    js = ""
    js = js + "{dialog.object}._urlToFetch = '" + url + "';" + crlf()
    js = js + "fetchFile2('" + js_escape(url) + "');"       // <-- I changed to fetchfile2 to trigger automatic download
    'note: if you want to automatically trigger the file download after the ajax callback has completed
    'change the call to fetchFile2().
    
    xb_getData = js
    I am stuck on how to make url an array instead of a single variable, and pass that along to fetchfile2, and have fetchfile2 parse it. Here is fetchfile2 code:

    Code:
    function fetchFile2(url) { 
    	var arr = [];
    	arr.push( {filename: url} );
    	var options = {
    		targetFolder: '__myAlphaFiles',
    		showProgress: true,
    		forceDownloadIfFileExists: true,
    		onComplete: function(array) { 
    			//alert('file was downloaded');
    			readFiles();
    		},
    		onError: function(array,arrayIndex) { 
    			alert('error');
    		},
    		progress: {
    			color: '#9fa1e8',
    			width: '300px',
    			allowCancel: false,
    			progressElement: '{dialog.componentname}.V.R1.PLACEHOLDER_1'
    		}
    	}
    	{dialog.object}.phoneGapFileDownload(arr,options);
    }
    Now, I'm guessing the fetchfile2 is already setup to handle an array, but I can't say for sure because I am not understanding all of it.

    Anyway, How do I make url above an array and pass multiple urls and is fetchfile2 already setup to handle that array?

    THANK YOU!!

    #2
    Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

    Without re-recreating the code, I'll take a stab at this. I believe something is missing from the fetchfile2 function. This function is accepting the 'url' parameter, which I'll assume is an array of filenames. If we look at the converted PhoneGap File Download Action we see...

    Code:
    var _list = window['getFiles']()
    var arr = [];
    for(var i = 0; i < _list.length; i++) { 
    	arr.push( {filename: _list[i]} );
    }
    var options = {
    	targetFolder: '__myFiles',
    	showProgress: false,
    	forceDownloadIfFileExists: true,
    	progress: {
    		color: '#9fa1e8',
    		width: '300px',
    		allowCancel: false,
    		progressElement: '{dialog.componentname}.V.R1.'
    	}
    }
    {dialog.object}.phoneGapFileDownload(arr,options);
    From this we can assume that .phoneGapFileDownload() can accept multiple files. arr is creating an array of JSON filenames from window['getfiles'] in this part of the code...

    Code:
    var _list = window['getFiles']()
    var arr = [];
    for(var i = 0; i < _list.length; i++) { 
    	arr.push( {filename: _list[i]} );
    }
    arr is now an array of filenames and passed into .phoneGapFileDownload.

    So... if your 'url' parameter is actually an array of filenames, then I believe you need to add this code to the top of fetchFile2

    Code:
    var arr = [];
    for(var i = 0; i < url.length; i++) { 
    	arr.push( {filename: url[i]} );
    }
    Your fetchFile2 function will now be...

    Code:
    function fetchFile2(url) { 
    	var arr = [];
    	for(var i = 0; i < url.length; i++) { 
    		arr.push( {filename: url} );
    	}
    	var options = {
    		targetFolder: '__myAlphaFiles',
    		showProgress: true,
    		forceDownloadIfFileExists: true,
    		onComplete: function(array) { 
    			//alert('file was downloaded');
    			readFiles();
    		},
    		onError: function(array,arrayIndex) { 
    			alert('error');
    		},
    		progress: {
    			color: '#9fa1e8',
    			width: '300px',
    			allowCancel: false,
    			progressElement: '{dialog.componentname}.V.R1.PLACEHOLDER_1'
    		}
    	}
    	{dialog.object}.phoneGapFileDownload(arr,options);
    }

    Comment


      #3
      Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

      Hi David,

      Thank you... I did try that, but I guess I'm stuck at on the XBasic side... how do I create the array (or is it JSON...or is that synonymous)?

      I appreciate the assistance!

      Comment


        #4
        Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

        Ok... understood.

        You're going to need to create a comma delimited list of filenames in XBasic. It's up to you how you do that, but extending the example... here is the code which creates 2 temp files in session storage. This code is starting at the point in your example where we get the url for the first file. After we get the first url, we go and create another file. At the point where we create the 2nd url, we create a comma delimited string of the 1st and 2nd url. You get the idea... whatever files you're dealing with, create a comma delimited string of filenames.

        Code:
        'get the URL for this session file
        dim url as c 
        url = Session.FormatFileDataURL(clientSideFileName)
        
        
        'now... do it all again to get a second file
        tempFN = request.GetRequestTempFileName(".json")
         
        'save the json data to the temporary file
        file.from_string(tempFn,json)
         
        clientSideFileName = remspecial(api_uuidcreate()) + ".json"
         
        'now put the temporary file into session storage
        session.SaveFileToSessionFile(tempFN,clientSideFileName)
        
        'now we have 2 temp fiels in session storage
        'since we have 2 files, we need to append to the existing url
        'we are passing a comma delimited string of filenames into the Javascript function
        'once there, we can turn our string into an array of filenames
        
        'get the URL for this session file
        url = url + "," + Session.FormatFileDataURL(clientSideFileName)
         
        'construct the Javascript response that will be sent to the client
        'note that we specify that a function called 'fetchFile()' should be called
        'on the client-side with the name of the URL that points to the temporary
        'file in session storage. This 'fetchFile()' function is a user-defined
        'Javascript function that you will need to add to your UX component
         
        dim js as c 
        js = js + "fetchFile('" + js_escape(url) + "');"
         
        'return the javascript code
        xb_getData = js

        Then, in the fetchFile Javascript function, take that comma delimited string of filenames and run it through the Javascript split() method. This turns the string into an array. Then, process the array, and off you go.

        Code:
        function fetchFile(url){
        
        	//url is a comma delimited list of filenames.  .split will split a string into an array of sub-strings
        	var _list = url.split(",");
        	var arr = [];
        	for(var i = 0; i < _list.length; i++) { 
        	    arr.push( {filename: _list[i]} );
        	}
        
        }

        Comment


          #5
          Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

          I seem much closer, thank you!!!! What does the arr.push actually do? I ask this because I tried to do:

          Code:
          function fetchFile2(url) { 
          
          	var _list = url.split(",");
          	
          	var arr = [];
          	for(var i = 0; i < _list.length; i++) { 
                          // this displays the passed thru URLs properly - i send 2 and both show up
          		alert('Downloading: ' + _list[i]);
          		arr.push( {filename: _list[i]} );
          	}
          	
          	
          	for(var ia = 0; ia < arr.length; ia++) {
                          // here I'm only getting Object.Object.  The phonegap plugin is only downloading the first file still..
          		alert('Updated: ' + arr[ia]);
          		}
          Thank you again!!!

          Comment


            #6
            Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

            not to take anything from david..
            you start with empty object arr[];
            then you add an item to it by pushing arr. push()
            thanks for reading

            gandhi

            version 11 3381 - 4096
            mysql backend
            http://www.alphawebprogramming.blogspot.com
            [email protected]
            Skype:[email protected]
            1 914 924 5171

            Comment


              #7
              Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

              Hi Gandhi, what do you mean? That's actually the code that Alpha uses in their examples, so I'm not sure how I should be initializing arr[] then?

              Thank you

              Comment


                #8
                Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                Code:
                Code:
                function fetchFile(url){
                
                	//url is a comma delimited list of filenames.  .split will split a string into an array of sub-strings
                	var _list = url.split(",");
                	var arr = [];
                	for(var i = 0; i < _list.length; i++) { 
                	    arr.push( {filename: _list[i]} );
                	}
                
                }
                this is the code you are talking about right?
                you start with an object arr[];
                and adding list of items to it by arr. push( {filename : _list[i]});
                thanks for reading

                gandhi

                version 11 3381 - 4096
                mysql backend
                http://www.alphawebprogramming.blogspot.com
                [email protected]
                Skype:[email protected]
                1 914 924 5171

                Comment


                  #9
                  Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                  You set up a Javascript variable arr as an array... var arr = []; The square brackets indicate an empty array.

                  arr.push(arrayItem); adds a new item to the end of that the arr array. This is how you build an array in Javascript

                  Comment


                    #10
                    Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                    Ok, got it.. and we have var arr = []; .... am I missing something?

                    Thank you guys!

                    Comment


                      #11
                      Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                      Why do you have...

                      Code:
                      	for(var ia = 0; ia < arr.length; ia++) {
                                      // here I'm only getting Object.Object.  The phonegap plugin is only downloading the first file still..
                      		alert('Updated: ' + arr[ia]);
                      		}
                      Is this code in here just for testing?

                      Comment


                        #12
                        Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                        Finally got it working guys!! THANK YOU!!!

                        Comment


                          #13
                          Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                          What was wrong?

                          Comment


                            #14
                            Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                            Yes that was for debugging purposes... sorry. I didn't realize I needed to add .filename to the end of the arr[ia] to display the filename.

                            Thanks again !!! I only spent 3 days trying to figure this out first. It took me about 5 weeks to figure out that the downloads via AA's download routine goes into files/files folder on android for some reason.. could be my issue, but seems that my code is identical.

                            Anyway, you have saved me weeks! THANK YOU AGAIN!

                            Comment


                              #15
                              Re: Phonegap FileDownload ... passing array of filenames from xbasic to javascript

                              I'm not sure what was wrong - except I had a space before http:// for the first url, and a space after the ,

                              Not sure if that would cause the second file to not download, or not..

                              Comment

                              Working...
                              X