Reputation: 11
[Update] Figured out the problem. See my answer in comment. Incognito mode could possibly be causing the problem too.
I desperately need help as this is supposed to be going Live really soon. The script used to work for both JPEG and MP4. After I committed a go live date, suddenly the script doesn't like MP4 file and just rejects it entirely. It knows........
Anyway, why is it that jpeg condition works fine, but not mp4? Below the script, I've added the comment where it fails too:
var file = "";
var getFile = "";
var width = "";
var height = "";
var findFile = DriveApp.getFilesByName(nameFile);
// actual script captures a file using its unique_file_name. It can be either jpeg or mp4
while (findFile.hasNext()) {
file = findFile.next();
}
Logger.log(file.getName());
//put a logger here to ensure that file iterator is capturing the file
if (file.getMimeType().includes("jpeg")) {
getFile = Drive.Files.get(file.getId(), { supportsAllDrives: true }).imageMediaMetadata
width = Drive.Files.get(file.getId(), { supportsAllDrives: true }).imageMediaMetadata.width
height = Drive.Files.get(file.getId(), { supportsAllDrives: true }).imageMediaMetadata.height
Logger.log("Image meta data:" + getFile);
//if the file is a jpeg file, the scripts completes this with all information accurately captured.
} else if (file.getMimeType().includes("mp4")) {
getFile = Drive.Files.get(file.getId(), { supportsAllDrives: true }).videoMediaMetadata
Logger.log("Video meta data:" + getFile);
//The script fails here. getFile is returned as undefined
width = Drive.Files.get(file.getId(), { supportsAllDrives: true }).videoMediaMetadata.width
height = Drive.Files.get(file.getId(), { supportsAllDrives: true }).videoMediaMetadata.height
duration = Drive.Files.get(file.getId(), { supportsAllDrives: true }).videoMediaMetadata.durationMillis
Logger.log("Video meta data:" + getFile);
}
Upvotes: 0
Views: 341
Reputation: 11
Turns out it's not a script problem:
The reason why this is happening is because the Google Drive is still "processing the video" - and therefore no metadata available.
Upvotes: 1