Alpha Video Training
Results 1 to 4 of 4

Thread: Abort File Upload To AmazonS3 If Length Of File Name Greater Than...

  1. #1
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,525

    Default Abort File Upload To AmazonS3 If Length Of File Name Greater Than...

    I am on build 5221-5152. I want to prevent the upload of a file (on a grid using File Upload to AmazonS3) IF the name of the selected file is greater than 100 in character length. This is because the size of the field in a table where I will be storing the name after the upload is 100. So I have tried putting some javascript in the After File Select property in the File Upload genie, which is supposed to abort the upload if the code includes: return false

    I want to, of course, give an alert to the user about why the upload was aborted.

    I am sure the issue I'm having is that I am STILL clumsy with javascript, so I thought someone might be kind enough to tell me what I'm doing wrong. Basically, using the code I guessed at below, nothing happens, whether file is greater than OR less than 100 characters.... no alert either way. The upload doesn't happen.
    Here is the code I am putting in the After File Select on the File Upload genie:
    Code:
    var fName = e.name;
    var nameLength = $u.s.toNum(length(fName));
    
    if(nameLength > 100){
    	alert('file name length is greater than 100');
    	return false;
    }
    I am just guessing with the length function because it showed up in the list Alpha shows. Any ideas?
    Last edited by kingcarol; 10-20-2019 at 10:08 AM.
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  2. #2
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,525

    Default Re: Abort File Upload To AmazonS3 If Length Of File Name Greater Than...

    So, I decided to go to school at W3 School, and changed the code to the following, but still get same result, nothing happens after I select the file to upload. BTW, the upload works fine if I remove the code in the After File Select.

    Code:
    //from W3 school:
    //var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    //var sln = txt.length;
    
    var fName = e.name;
    var nameLength = fName.length;
    
    if(nameLength > 100){
    	alert('file name length is greater than 100');
    	return false;
    }
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  3. #3
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,525

    Default Re: Abort File Upload To AmazonS3 If Length Of File Name Greater Than...

    So, another option is that The record that has the file name cannot be saved if the file name is too long and submitting it causes an error, which I know how to capture and let user know why. Since I am new to using Amazon S3 for uploads, I would then like to programmatically delete the file that did get uploaded, if I can’t save the record that refers to it. But I don’t know how to do delete a file on S3 through code. I know how to delete a file on our own server, but I bet it’s different when file is on S3. Does anybody have the code for that?
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  4. #4
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,525

    Default Re: Abort File Upload To AmazonS3 If Length Of File Name Greater Than...

    UPDATE! This has been solved (thanks to Robin Bennett). The solution is:

    Code:
    //Per Robin Bennett:  Because you can upload more than one item, e is actually an array.  
    //So you can find the length of the first filename like this:
     
    if (e[0].name.length > 100) {
    	alert('file name length is greater than 100');
    	return false;
    }
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

Similar Threads

  1. File Upload File Type Error Message Locks Up App
    By swest in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 07-11-2018, 01:00 PM
  2. File Upload - Upload a file to a server on internal network
    By swest in forum Application Server Version 11 - Web/Browser Applications
    Replies: 12
    Last Post: 08-28-2013, 11:52 AM
  3. File Upload/Download - Manually insert uploaded file into the database....
    By dionmccormick in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 07-16-2013, 11:49 AM
  4. File Upload Action Script Not Honoring File Type Restrictions
    By iRadiate in forum Mobile & Browser Applications
    Replies: 6
    Last Post: 07-11-2013, 12:53 PM
  5. Getting the folder location on file upload and file download javascript
    By acceptthis in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 03-09-2013, 07:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •