0

I am using Gmail api to get hold of an attachment using node as follows :

request({
        url: "https://www.googleapis.com/gmail/v1/users/xyz@gmail.com/messages/messageid/attachments/attachmentId",
        method: "GET",
        headers: {
        Authorization: 'Bearer token'
        },
        json: true
    }, function(error, response) {
        let myData = response.body.data;
        let file_data = URLSafeBase64.decode(utf8.encode(myData));
        fs.writeFileSync('path/new_file.pdf', file_data);
)};

And I am able to save the same locally. I need to write file_data to a new file and convert the same into a pdf one. I want this directly to happen in firebase storage i.e. I want to create and edit a file and change the corresponding extension as well. Is it possible ?

Soumya Kanti Naskar
  • 1,021
  • 3
  • 16
  • 29
  • Did you already try any interaction with Firebase Storage? It's API is relatively straightforward and you should be able to fairly simply upload the data from the local file like for example shown here: https://stackoverflow.com/questions/48919153/upload-file-to-google-cloud-storage-with-nodejs – Frank van Puffelen Jun 26 '20 at 03:30
  • Actually I don't want to do `fs.writeFileSync('path/new_file.pdf', file_data);` I want to directly write to the firebase storage – Soumya Kanti Naskar Jun 26 '20 at 03:41
  • There is no way to post data from a URL directly to Cloud Storage. You'll have to read it into the client first, either as a file, or as a stream. See https://stackoverflow.com/questions/54235721/transfer-file-from-url-to-cloud-storage – Frank van Puffelen Jun 26 '20 at 04:28

0 Answers0