Upload link of image from drive to spreadsheet only written "https://drive.google.com/uc?export=view"

Hi community

I am making CRUD apps of monitoring works. I am facing with a little struggle to when update some data after link of image has been sent to spreadsheet.
This image show before update has been performed

Then, i open my update screen, i get the that link of image/photo easily and store to label Urlphoto

. it should send the same link after i perform update action
this is some of my web app script

image

my question is after performed update action, why the link of image change just to be "https://drive.google.com/uc?export=view" ? where is the imageID? why is it not same with previouse link? Meanwhile, the link in Urlphot label has save same link with previous one before update

I hope you understand what i mean and please help me

Please show your full script, especially from your second script image. I believe it may have something to do with variable scopes.

Firstly, i want to say thank you that i am using your script to upload the image to gdrive and get the viewurl.

here is my script to perform update

/Update

    if (e.parameter.func == "Update") {

        if (e.parameters.filename && e.parameters.file && e.parameters.imageformat) {

    var imgf = e.parameters.imageformat[0].toUpperCase();

    var mime =

        (imgf == 'BMP')  ? MimeType.BMP

      : (imgf == 'GIF')  ? MimeType.GIF

      : (imgf == 'JPEG') ? MimeType.JPEG

      : (imgf == 'JPG')  ? MimeType.JPEG

      : (imgf == 'PNG')  ? MimeType.PNG

      : (imgf == 'SVG')  ? MimeType.SVG

      : false;

    if (mime) {

      var data = Utilities.base64Decode(e.parameters.file, Utilities.Charset.UTF_8);

      var blob = Utilities.newBlob(data, mime, e.parameters.filename);

      var imageID = DriveApp.getFolderById('1Vo4KWE6XLfJzqi3qagfUN-e84r2ae12E').createFile(blob).getId();

      var viewurl = "https://drive.google.com/uc?export=view&id=" + imageID;

           

    }

  }

    var weekNo = e.parameter.WEEKNO;

    var woNo = e.parameter.WONO;

    var woDesc = e.parameter.WODESC;

    var shop = e.parameter.SHOP;

    var activity = e.parameter.ACTIVITY;

    var startExecDate = e.parameter.STARTEXECDATE;

    var startExecTime = e.parameter.STARTEXECTIME;

    var finishExecTime = e.parameter.FINISHEXECTIME;

    var workStatus = e.parameter.WORKSTATUS

    var progress = e.parameter.PROGRESS;

    var pic = e.parameter.PIC;

    var linkPhoto = e.parameter.PHOTO

    if (typeof linkPhoto === "string" && linkPhoto.length === 0) {

      var photo = viewurl;

    } else {

      var photo = linkPhoto

    }

    //var photo = viewurl;

    var lr= sh.getLastRow();

    for(var i=1;i<=lr;i++){

      var data_id = sh.getRange(i, 2).getValue();

      //var tanggal_id = sh.getRange(i, 6).getValue();

      if(data_id==woNo){

       sh.getRange(i, 1).setValue(weekNo);

       sh.getRange(i, 3).setValue(woDesc);

       sh.getRange(i, 4).setValue(shop);

       sh.getRange(i, 5).setValue(activity);

       sh.getRange(i, 6).setValue(startExecDate);

       sh.getRange(i, 7).setValue(startExecTime);

       sh.getRange(i, 8).setValue(finishExecTime);

       sh.getRange(i, 9).setValue(workStatus);

       sh.getRange(i, 10).setValue(progress);

       sh.getRange(i, 11).setValue(pic);

       sh.getRange(i, 12).setValue(photo);

       return message ("Success: Data berhasil di Update");

        //return ContentService.createTextOutput("Data berhasil di Update").setMimeType(ContentService.MimeType.TEXT);

       

      }

    }

     

  }

function message(msg) {

 return ContentService.createTextOutput(JSON.stringify({Result: msg })).setMimeType(ContentService.MimeType.JSON);

}

and this is my block to perform update action

Please help me

Do you create the original photo and link on the spreadsheet in the same way from your app?

first, when user create a set of data (include photo) they pick the image from their local phone, and the image Will be upload to my Drive and the viewurl of image Will be put on my spreadsheet

then, when the user want to update that data.. first i use read function to read the data include view url, and the url i store it to a label (called urlPhoto label).

after the user change any data, and when they click update button, i use update function with expectation, the viewurl of previous one is same with after update action, because the user didn't change the image when update data.

But, actually the result is not like my expextation.. the viewurl is cutted and change to like my first post, the image id is lost.

is there any fault on my block or my script?

Thank you TimAi2i

It is most likely the script

The first test is:
if (e.parameters.filename && e.parameters.file && e.parameters.imageformat)

these parameters just have to exist, the script doesn't care if they are empty or not, therefore the variable viewurl is generated (without an image ID !)

Try changing the first test to:

if (e.parameters.filename && e.parameters.file && e.parameters.file != "" && e.parameters.imageformat )

Also you may want to change your viewurl to just:

https://drive.google.com/uc?id=

No, i don't want to make the url only https://drive.google.com/uc?id=. i want the complet url include image id

in my opinion, when user want to update the data except image, it's ok if 3 paramaters ( filename, file, imageformat) are not exist, because the imageurl has been existed from spreadsheet that i store it to urlphoto label. So when user click update button, i hope the image url is still same, because i use e.parameter.PHOTO to get image url from urlPhoto label in my block.

that's true, that the 3 parameters shall exist when user in step create. but in update step, we assume the url image has been created from step create. so i want to keep that image url, when to user want to update any data except the photo(not picking any image anymore), but the result the image url is cutted and image id is gone

That is up to you, just a suggestion.....

then what has the issue been from the beginning of this topic ?

the issue is the image url was changed when create and after update. I expect the image url keep same. how the way to make that, any another way?

i think the key is in this script.

var linkPhoto = e.parameter.PHOTO

if (typeof linkPhoto === "string" && linkPhoto.length === 0) {

  var photo = viewurl;

} else {

  var photo = linkPhoto

}

please check and give advise

Did you try my suggested script change?

Dear TimAI2, sorry in last 2 days i could not continue my project

Yes, i have just tried your suggestion, and the result is still same. The url of image is truncated

I believe I have found the issue.

When "uploading" the existing image url, try using a UriEncode block, just on the url. It needs encoding because of the &.

That should be on your UrlPhoto.Text block

It is a tricky one to spot, because it doesn't throw an error :wink:

Sorry, what i understand is i shall to use UriEncode the UrlPhoto.Text block before updating action? Please correct me, better to share the block what you mean. :slight_smile:

From this:

image

to this:

image