Search code examples
angularwysiwygfroala

Froala editor, rename the file while upload


Currently I'm using the froala editor with Angular and upload the file using AWS S3 service.

I want to rename the file before its upload to S3. So I use the event which is already present in froala, which is 'file.beforeUpload'

I'm getting the object as 'FileList'. With that I can't change the filename.

With that event I couldn't rename the file. Anyone help on this?


Solution

  • Actually froala editor itself appending the timestamp before the file name to avoid naming issue.

    You have two option on front-end as well as in back-end,

    Front-end:

    After getting the AWS hash key, you're setting the value like this,

    this.options['imageUploadToS3'] = aws_hash_key;
    

    before this, you can update the keyStart value by using the properties,

    data.KeyStart = your_unique_name_come_here; 
    

    Back-End:

    While getting the AWS hash key API itself you can set the unique name as start value, like this,

    const configs = {
        bucket: 'stackOverflow',
        region: 'us2-west',
        keyStart: / + `your_unique_name_come_here`,
        acl: 'public-read',
        accessKey: XXXXXXXXXXXXXXXXXXXX,
        secretKey: XXXXXXXXXXXXXXXXXXXX
      };
      return FroalaEditor.S3.getHash(configs);