Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API - Automated Queries Message

I am using this Ghost plugin to store image data on Google Drive. Recently, images have stopped loading with this error page downloaded in place of the image:

https://github.com/robincsamuel/ghost-google-drive

The site is running in a containerized Ghost instance on Google Cloud Run, source here

Do I need to open a support ticket somewhere to resolve this? Site in question is here

EDIT: Here is the code used to access the saved content.

jwtClient.authorize(function(err, tokens) {
        if (err) {
          return next(err);
        }
        const drive = google.drive({
          version: API_VERSION,
          auth: jwtClient
        });
        drive.files.get(
          {
            fileId: id
          },
          function(err, response) {
            if (!err) {
              const file = response.data;
              const newReq = https
                .request(
                  file.downloadUrl + "&access_token=" + tokens.access_token,
                  function(newRes) {
                    // Modify google headers here to cache!
                    const headers = newRes.headers;
                    headers["content-disposition"] =
                      "attachment; filename=" + file.originalFilename;
                    headers["cache-control"] = "public, max-age=1209600";
                    delete headers["expires"];

                    res.writeHead(newRes.statusCode, headers);
                    // pipe the file
                    newRes.pipe(res);
                  }
                )
                .on("error", function(err) {
                  console.log(err);
                  res.statusCode = 500;
                  res.end();
                });
              req.pipe(newReq);
            } else {
              next(err);
            }
          }
        );
      });
like image 461
Beshoy Hanna Avatar asked Feb 13 '20 19:02

Beshoy Hanna


1 Answers

Your problem is related to file.downloadUrl. This field is not guaranteed to work and is not supposed to be used to download files.

The correct way to do this is to use the webContentLink property instead. You can look at here for reference.

like image 161
ZektorH Avatar answered Oct 09 '22 03:10

ZektorH