Spaces:
Running
on
Zero
Running
on
Zero
import { Drive } from '@google-cloud/drive'; | |
import { doPost } from './LineMock'; | |
const drive = new Drive(); | |
export class LineImageSaver { | |
doPost(e: any) { | |
const imageData = e.postData.contents; | |
this.saveImageToDrive(imageData); | |
} | |
saveImageToDrive(imageData: string) { | |
const file = drive.files.insert({ | |
resource: { | |
title: 'Line Image', | |
mimeType: 'image/jpeg', | |
}, | |
media: { | |
mimeType: 'image/jpeg', | |
body: Buffer.from(imageData, 'base64'), | |
}, | |
}); | |
console.log(`Image saved to Drive: ${file.id}`); | |
} | |
} |