Upload image directly to AWS S3 using pre-signed URL

In an attempt to send the image directly to S3 with a signed url, I added the necessary attributes to the customFormData and the request is performed correctly. Two points prevent this functionality from being a success.


1 - The UploadFiles attribute of the formData where the file binary is sent, should be "file", AWS expects this attribute name.


2 - The order of the formData attributes is relevant, when AWS identifies the "file" attribute at the beginning, all other parameters are discarded. The "file" attribute must be added to the end of all added customFormData attributes.


6 Replies

VJ Vinitha Jeyakumar Syncfusion Team January 11, 2023 12:41 PM UTC

Hi Glauber,

Query 1. "The UploadFiles attribute of the formData where the file binary is sent, should be "file", AWS expects this attribute name."

Your requirement to change the "UploadFiles" name attribute to "file" can be achieved by using the dialogOpen event of the RichTextEditor,

Code snippet:
<ejs-richtexteditor
    id="defaultRTE"
    (dialogOpen)="dialogOpen($event)"
  >
  </ejs-richtexteditor>

 public dialogOpen() {
    (document.getElementsByClassName('e-uploader')[0as any).name = 'file';
  }




Query 2. The order of the formData attributes is relevant, when AWS identifies the "file" attribute at the beginning, all other parameters are discarded. The "file" attribute must be added to the end of all added customFormData attributes"

Currently, we are checking with the possibilities, we will update you the further details on or before 13th January 2023.

Regards,
Vinitha




GL Glauber replied to Vinitha Jeyakumar January 18, 2023 03:13 PM UTC

Hi Vinitha, 


any news?


Regards, 

Glauber



GL Glauber January 25, 2023 01:23 PM UTC

Hello, any updates on this topic?


Regards, 

Glauber



BS Buvana Sathasivam Syncfusion Team January 27, 2023 04:48 PM UTC

Hi Glauber,


We apologize for the delay in response. To change the order of the Form Data, you can use the following code in the ngOnInit method. This will override the uploadFilesRequest method at the source level.


 ngOnInit() {

    (Uploader as any).prototype.uploadFilesRequest = function (

      selectedFilesFileInfo[],

      inumber,

      custom?: boolean

    ) {

      const cloneFilesBlob[] = [];

      const chunkEnabledboolean = this.checkChunkUpload();

      const ajaxAjax = new Ajax(

        this.asyncSettings.saveUrl,

        'POST',

        true,

        null

      );

      ajax.emitError = false;

      let getFileDataFileInfo[];

      const eventArgsUploadingEventArgs = {

        fileData: selectedFiles[i as number],

        customFormData: [],

        cancel: false,

      };

      const formDataFormData = new FormData();

      ajax.beforeSend = (eBeforeSendEventArgs=> {

        eventArgs.currentRequest = ajax.httpRequest;

        this.trigger(

          'uploading',

          eventArgs,

          (eventArgsUploadingEventArgs=> {

            /* istanbul ignore next */

            if (eventArgs.cancel) {

              this.eventCancelByArgs(eeventArgsselectedFiles[i as number]);

            }

            this.updateFormData(formDataeventArgs.customFormData);

            const namestring = this.element.getAttribute('name');

            formData.append(

              name,

              selectedFiles[i as number].rawFile,

              selectedFiles[i as number].name

            );

          }

        );

      };

      if (selectedFiles[i as number].statusCode === '1') {

        if (

          chunkEnabled &&

          selectedFiles[i as number].size > this.asyncSettings.chunkSize

        ) {

          this.chunkUpload(selectedFiles[i as number], customi);

        } else {

          ajax.onLoad = (eEvent): object => {

            if (eventArgs.cancel) {

              return {};

            } else {

              this.uploadComplete(eselectedFiles[i as number], custom);

              return {};

            }

          };

          ajax.onUploadProgress = (eEvent): object => {

            if (eventArgs.cancel) {

              return {};

            } else {

              this.uploadInProgress(

                e,

                selectedFiles[i as number],

                custom,

                ajax

              );

              return {};

            }

          };

          /* istanbul ignore next */

          ajax.onError = (eEvent=> {

            this.uploadFailed(eselectedFiles[i as number]);

            return {};

          };

          ajax.send(formData);

        }

      }

    };

  }


Please note that you should run the service provided in the link https://www.syncfusion.com/downloads/support/directtrac/general/ze/ImageUpload_RTE1737757220-1854469404 before running the sample code at https://stackblitz.com/edit/angular-tnzt6z?file=src%2Fapp.component.html,src%2Fapp.component.ts,package.json

Regards,

Buvana S



GL Glauber February 22, 2023 07:35 PM UTC

Buvana, the presented solution worked.


Thanks.



VY Vinothkumar Yuvaraj Syncfusion Team February 23, 2023 02:59 PM UTC

Hi Glauber,


We are happy to hear your problem has been solved. Please let us know if you have any further queries. 


Regards,

Vinothkumar


Loader.
Up arrow icon