guestbook/static/js/index.js
/*
  Function to carry out the actual POST request to S3 using the signed request from the Python app.
*/
Function to carry out the actual POST request to S3 using the signed request from the Python app.
Function to carry out the actual POST request to S3 using the signed request from the Python app .
function uploadFile(file, signedResponseData){
  const s3Data = signedResponseData.s3Data;
  const xhr = new XMLHttpRequest();
  xhr.open('POST', s3Data.url);
  xhr.setRequestHeader('x-amz-acl', 'public-read');
  const postData = new FormData();
  for(key in s3Data.fields){
    postData.append(key, s3Data.fields[key]);
  }
  postData.append('file', file);
  xhr.onreadystatechange = () => {
    if(xhr.readyState === 4){
      if(xhr.status === 200 || xhr.status === 204){
        console.log("Upload complete for file! object key:", s3Data.fields.key)
        if (file.type.indexOf('video/') !== -1) {
          state_machine.trigger_stream_prep();
          triggerStreamingPrep(signedResponseData);
        } else {
          state_machine.finalize_submit();
        }
      }
      else{
        state_machine.abort_submit();
        alert('Could not upload file.');
      }
    }
  };
  xhr.upload.addEventListener("progress", progressHandler);
  xhr.addEventListener('error', (e) => {
    XHR_ERROR_MESSAGE = e;
    state_machine.abort_submit();
  });
  xhr.send(postData);
}
function uploadFile ( file , signedResponseData ) { const s3Data = signedResponseData . s3Data ; const xhr = new XMLHttpRequest ( ) ; xhr . open ( 'POST' , s3Data . url ) ; xhr . setRequestHeader ( 'x-amz-acl' , 'public-read' ) ; const postData = new FormData ( ) ; for ( key in s3Data . fields ) { postData . append ( key , s3Data . fields [ key ] ) ; } postData . append ( 'file' , file ) ; xhr . onreadystatechange = ( ) => { if ( xhr . readyState === 4 ) { if ( xhr . status === 200 || xhr . status === 204 ) { console . log ( "Upload complete for file! object key:" , s3Data . fields . key ) if ( file . type . indexOf ( 'video/' ) !== - 1 ) { state_machine . trigger_stream_prep ( ) ; triggerStreamingPrep ( signedResponseData ) ; } else { state_machine . finalize_submit ( ) ; } } else { state_machine . abort_submit ( ) ; alert ( 'Could not upload file.' ) ; } } } ; xhr . upload . addEventListener ( "progress" , progressHandler ) ; xhr . addEventListener ( 'error' , ( e ) => { XHR_ERROR_MESSAGE = e ; state_machine . abort_submit ( ) ; } ) ; xhr . send ( postData ) ; }
Function to carry out the actual POST request to S3 using the signed request from the Python app.
Function to carry out the actual POST request to S3 using the signed request from the Python app .