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

Amazon File upload - stop if duplicate file

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

    Amazon File upload - stop if duplicate file

    I have an issue with the Amazon File upload that I've been struggling with for 2 days.

    In the After File Select, I have an Xbasic callback to check if a file exists in the database and this works. I then set a state variable (have also tried a control), and based on the variable or control decide whether to continue or not.

    It all works, but the timing is off somewhere such that it can't read the variable or control until after the callback and by then it's already completed the upload which I want to abort by using "return false", but it uploads anyway.

    I have tried using timeouts and moving things around but nothing has yet worked for me.

    Please help. Can post my (mostly) working code if needed.

    #2
    I'm attaching my current code in case someone is able to suggest anything.

    portion of Xbasic code to set the control or state variable (this works):

    Code:
        countfiles=p.rs.data(1)
        if countfiles>0 then
            e._state.canUpload="no"
            e._set.upload.value="no"
             dim js as c =<<%js%
            var obj = {};
            obj['canUpload'] = 'no';        
            {dialog.object}.setStateInfo(obj);
            %js%
        else
            e._state.canUpload="yes"
            e._set.upload.value="yes"
             dim js as c =<<%js%
            var obj = {};
            obj['canUpload'] = 'yes';        
            {dialog.object}.setStateInfo(obj);
            %js%
        end if
    
    checkDuplicates=js​

    current Javascript in the "After File Select" of the S3 Upload Action:

    Code:
    {dialog.object}.setValue('upload','');
    
    for(var i=0; i < e.length; i++) {
        //check for invalid characters
        var match = (new RegExp('[<>:*"?&#%(){}+\\\/\|]|\\.\\.|^\\.|\\.$')).test(e[i]["name"]);
        if (match) {
            {dialog.object}.setValue('upload','no');
            var title = 'Invalid Filename';
            var html = '<p style="padding:10px;text-align:center;">Invalid file name. The name of the attached file (<b>'+e[i]["name"]+'</b>) contains invalid characters. <br><br>Please rename your file without special characters before attaching.</p>'
            var type = 'o';
            var onClose = function (btn) {};
            A5.msgBox.show(title, html, type,onClose);
            return false;
        }
    
        //check for duplicate filenames
        var network={dialog.object}.getSessionVariable('Network');
        var addData ='_shortname='+e[i]["name"]+
        '&_network='+network;
               {dialog.Object}.ajaxCallback('','','checkDuplicates','',addData);
               thisFilename=e[i]["name"];    
    
        //wait for callback to complete and get updated value of upload control
        canUpload={dialog.object}.getValue('upload');
        if(canUpload=="no"){
            var title = 'Duplicate Found';
            var html = '<p style="padding:10px;text-align:center;">A file with the name '+ thisFilename+' already exists.<br><br>Please Delete or Update instead.</p>'
            var type = 'o';
            var onClose = function (btn) {};
            A5.msgBox.show(title, html, type,onClose);
            return false;
        }          
    
    
    
    }​
    The filename invalid characters works like a charm.
    The Ajax callback works, but it checks the "canUpload" value before it completes the callback. I have tried wrapping things in a setTimeout, putting the checks in the OnComplete portion of the Ajax Callback, and many other options, but I have not been able to get it to correctly get the value returned from the callback, which means it will ALWAYS continue to upload a file even though I've checked and marked it as a duplicate.

    Very, very frustrating!

    Comment


      #3
      Silly question.
      Why are you uploading dupe named files anyway?
      Any reason you cannot tag a file when it is uploaded and check at the source?
      Else, try splitting the process into 2.
      See our Hybrid Option here;
      https://hybridapps.example-software.com/


      Apologies to anyone I haven't managed to upset yet.
      You are held in a queue and I will get to you soon.

      Comment


        #4
        My guess he’s trying to prevent end users from uploading duplicate files.
        Gregg
        https://paiza.io is a great site to test and share sql code

        Comment


          #5
          Yep, my guess too but he hasn't said that as yet.
          What constitutes a duplicate? Not just a file name IMHO.
          Something like "if exists, rename +1" on upload ?

          Not sure we know enough about the process. We'll me, anyway.

          What about "object cancel" if there is a dupe?
          Last edited by Ted Giles; 03-07-2024, 02:32 PM.
          See our Hybrid Option here;
          https://hybridapps.example-software.com/


          Apologies to anyone I haven't managed to upset yet.
          You are held in a queue and I will get to you soon.

          Comment


            #6
            we can’t see all his code, but based on what we can see it looks like he’s doing a query that is likely to involve the file name; and if he gets any number of rows greater than 0, it’s considered a duplicate.
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              Yes the last is the correct guess. I'm trying
              ​​to prevent users uploading a file with an existing name because by default, it will overwrite the file already in S3 and, in this case, add a new entry to the database. If they need to replace an existing file with a newer version, I'll need them to specifically update the file and maintain the same reference in the database. Links to files are used in other parts of the system so it needs to be maintained.

              From what I can work out, there is no other place I can check what filename the user has selected until the After File Select occurs so I have to do the comparison there.

              There is also no other place to cancel the upload after the file has been selected except for in that same section, because the next process is the On Progress event.

              If I could check the database in JavaScript without doing an Ajax callback, I believe it would work ok. It's just the waiting for the callback that seems to mess with the timing.

              Ted's suggestion to rename if exists wouldn't work either, because I'd have to wait for an Ajax callback to see if the filename exists, which is what I'm already doing. The JavaScript continues before the callback has finished, which is the exact same problem I'm having. And I don't want to rename it for reasons I mentioned above, just abort it and give them a message.

              Comment


                #8
                You can , but it depends on how many items you have in your database.
                Until I get the IAM user policy stuff figured out for my Wasabi account, I'm making creative guesses.

                Have you considered a 2-step (one step to the user), where you get the filename(s) first, then if they are not duplicates,
                process the upload procedure ?
                Gregg
                https://paiza.io is a great site to test and share sql code

                Comment


                  #9
                  Originally posted by madtowng View Post
                  Have you considered a 2-step (one step to the user), where you get the filename(s) first, then if they are not duplicates,
                  process the upload procedure ?
                  I'm not even sure where to begin making it a 2-step process.

                  The Upload to S3 action is an all-in-one so by your suggestion, I could only see doing this 2 times - once to select the file to upload, store it somewhere and check it, then doing it again to continue uploading or remove the temporary stored file?



                  Comment


                    #10
                    I would do the file check when the user submits the file name,.
                    proceed with the upload if the file is not a duplicate .
                    Gregg
                    https://paiza.io is a great site to test and share sql code

                    Comment


                      #11
                      I understand the process you're suggesting. Not sure how to execute.

                      How do I get the user to submit a file name, and then process that file if it's not a duplicate?

                      Comment


                        #12
                        I would run the ajax callback, setting a state variable to either proceed or halt. In the javascript action, i would configure before select to return false if that state variable == halt.
                        Gregg
                        https://paiza.io is a great site to test and share sql code

                        Comment


                          #13
                          you can do this all in the javascript action, be sure to check the run synchronous box.
                          Gregg
                          https://paiza.io is a great site to test and share sql code

                          Comment


                            #14
                            Originally posted by madtowng View Post
                            I would run the ajax callback, setting a state variable to either proceed or halt. In the javascript action, i would configure before select to return false if that state variable == halt.
                            You're suggesting in the Upload to Amazon S3 action that in the Before File Select event I return false based on whether it's a duplicate or not? If that's the case, I don't have access to the filename until the After File Select event.

                            In the Javascript action, there is only one action - File Upload - Amazon S3 Storage. It contains the Before File Select and After File Select javascript options. Unless you mean create another Action javascript insde the After File Select event, that does things in order - I'll try that.

                            Comment


                              #15
                              I hope this helps.

                              image.png
                              Gregg
                              https://paiza.io is a great site to test and share sql code

                              Comment

                              Working...
                              X