Can I overwrite an image file using Google Apps Script? I tried:
file.setContent(newBlobImage);
file.replace(newBlobImage);
None of them work. .setContent()will delete all the data in the file, and it looks like it just writes the variable name in the form of text or something like that. I assume that both .setContent()and .replace()are used for text documents, and perhaps why they do not work.
If it was a text file or a spreadsheet, I could clear it and then add new content.
I can destroy the file and then create a new one, but I would prefer if there is another way.
If I write a file with the same name, it will not overwrite the existing file, it creates another file with the same name.
The only way I was able to delete the file was DocsList, and the only success I had when creating the image file was DriveApp. So I have to delete the file using DocsList, and then create another file with DriveApp.
Well, I figured out how to delete a file without sending it to the trash, so I wonβt need to empty the trash later. Google Drive SDKinside the Script application has a method removethat did not send the file to the trash, it just disappeared.
var myFolder = DriveApp.getFolderById('3Bg2dKau456ySkhNBWB98W5sSTM');
thisFile = myFolder.getFilesByName(myFileName);
while (thisFile.hasNext()) {
var eachFile = thisFile.next();
var idToDLET = eachFile.getId();
Logger.log('idToDLET: ' + idToDLET);
var rtrnFromDLET = Drive.Files.remove(idToDLET);
};
, DriveApp DriveAPI, , . DriveAPI.remove , , , , . , , , , , .
, DriveAPI Patch Update.
.patch(resource, fileId, optionalArgs)
Google .
resource - , , . fileId . , optionalArgs , HTTP-? .
, . - PUT,
, .
. Patch, . , , , .
Patch, Update:
.update(resource, fileId, mediaData)
mediaData blob. , , . , resource. .