app/ui/javascript/util.js
// this function will upload the image to COS and get signedurls for uploaded images
this function will upload the image to COS and get signedurls for uploaded images
this function will upload the image to COS and get signedurls for uploaded images
async function uploadImageAndGetProcessedImages() {
  const timestamp = Date.now();
  const file = document.getElementById('theFile').files[0];
  const filename = file.name;
  const indexOfLastPeriod = filename.lastIndexOf('.');
  const newFileName = [filename.slice(0, indexOfLastPeriod), '_', timestamp, filename.slice(indexOfLastPeriod, filename.length)].join('')
  const form = document.getElementById('myform');
  const data = new FormData(form);
  data.set('body', file, newFileName);
  try {
    const response = await $.ajax({
      type: 'POST',
      enctype: 'multipart/form-data',
      url: '/write',
      data,
      processData: false,
      contentType: false,
      cache: false,
      timeout: 60000,
    });
    const image = document.getElementById('original-image');
    image.src = response.url;
    const grayUrl = await getSignedUrl(newFileName, '_grey.png');
    const vrUrl = await getSignedUrl(newFileName, '_vr.txt');
    setTimeout(() => { tryTextUrl(vrUrl); }, 15000);
    setTimeout(() => { tryUrl(grayUrl); }, 15000);
  } catch (error) {
    console.log('ERROR : ', error);
  }
}
async function uploadImageAndGetProcessedImages ( ) { const timestamp = Date . now ( ) ; const file = document . getElementById ( 'theFile' ) . files [ 0 ] ; const filename = file . name ; const indexOfLastPeriod = filename . lastIndexOf ( '.' ) ; const newFileName = [ filename . slice ( 0 , indexOfLastPeriod ) , '_' , timestamp , filename . slice ( indexOfLastPeriod , filename . length ) ] . join ( '' ) const form = document . getElementById ( 'myform' ) ; const data = new FormData ( form ) ; data . set ( 'body' , file , newFileName ) ; try { const response = await $ . ajax ( { type : 'POST' , enctype : 'multipart/form-data' , url : '/write' , data , processData : false , contentType : false , cache : false , timeout : 60000 , } ) ; const image = document . getElementById ( 'original-image' ) ; image . src = response . url ; const grayUrl = await getSignedUrl ( newFileName , '_grey.png' ) ; const vrUrl = await getSignedUrl ( newFileName , '_vr.txt' ) ; setTimeout ( ( ) => { tryTextUrl ( vrUrl ) ; } , 15000 ) ; setTimeout ( ( ) => { tryUrl ( grayUrl ) ; } , 15000 ) ; } catch ( error ) { console . log ( 'ERROR : ' , error ) ; } }
this function will upload the image to COS and get signedurls for uploaded images
this function will upload the image to COS and get signedurls for uploaded images
// set the filename as uploadedName_timestamp.extension // create the formdata with new filename