
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
google-drive-uploader-js
Advanced tools
A Node.js module for uploading, downloading, and managing files on Google Drive using OAuth2 authentication
A simple and powerful Node.js module for uploading, downloading, and managing files on Google Drive using OAuth2 authentication.
npm install google-drive-uploader-js
Before using this module, you need to:
For detailed setup instructions, visit the Google Drive API documentation.
const GoogleDriveUploader = require('google-drive-uploader-js');
// Initialize the uploader
const uploader = new GoogleDriveUploader(
'your-client-id',
'your-client-secret',
'your-refresh-token'
);
async function uploadFile() {
try {
const result = await uploader.uploadFile(
'./local-file.pdf', // Local file path
'folder-id-on-drive', // Google Drive folder ID
'custom-filename.pdf' // Optional: custom filename
);
console.log('File uploaded:', result.id);
} catch (error) {
console.error('Upload failed:', error.message);
}
}
uploadFile();
async function uploadFromBuffer() {
const fileData = Buffer.from('Hello World!', 'utf8');
try {
const result = await uploader.uploadFileFromData(
fileData,
'hello.txt',
'folder-id-on-drive',
'text/plain'
);
console.log('Buffer uploaded:', result.id);
} catch (error) {
console.error('Upload failed:', error.message);
}
}
async function createFolder() {
try {
const folder = await uploader.createFolder(
'My New Folder',
'parent-folder-id' // Optional: parent folder ID
);
console.log('Folder created:', folder.id);
} catch (error) {
console.error('Folder creation failed:', error.message);
}
}
async function listFiles() {
try {
const files = await uploader.getFiles('folder-id');
files.forEach(file => {
console.log(`${file.name} (${file.id})`);
});
} catch (error) {
console.error('Failed to list files:', error.message);
}
}
async function downloadFile() {
try {
const fileContent = await uploader.downloadFileContent('file-id');
// Save to local filesystem
const fs = require('fs');
fs.writeFileSync('./downloaded-file.pdf', fileContent);
console.log('File downloaded successfully');
} catch (error) {
console.error('Download failed:', error.message);
}
}
async function deleteFile() {
try {
await uploader.deleteFile('file-id');
console.log('File deleted successfully');
} catch (error) {
console.error('Delete failed:', error.message);
}
}
new GoogleDriveUploader(clientId, clientSecret, refreshToken)
uploadFile(filePath, folderId, customName?)
- Upload file from filesystemuploadFileFromData(fileData, filename, folderId, mimeType?)
- Upload from buffergetFiles(folderId)
- List files in foldergetFileById(fileId, name?)
- Get file informationdeleteFile(fileId)
- Delete a filecreateFolder(name, parentFolderId?)
- Create a folderfolderExists(name, parentFolderId?)
- Check if folder existsdownloadFileContent(fileId)
- Download file contentgetMimeType(filePath)
- Get MIME type for fileAll methods return promises and should be wrapped in try-catch blocks or use .catch()
for proper error handling.
try {
const result = await uploader.uploadFile('./file.pdf', 'folder-id');
} catch (error) {
if (error.message.includes('File not found')) {
console.error('Local file does not exist');
} else if (error.message.includes('Failed to get access token')) {
console.error('Authentication failed - check your credentials');
} else {
console.error('Upload error:', error.message);
}
}
The module automatically detects MIME types for common file extensions:
.pdf
, .doc
, .docx
, .txt
.jpg
, .jpeg
, .png
.zip
.xls
, .xlsx
.mp3
, .wav
, .aac
, .m4a
For unsupported extensions, it defaults to application/octet-stream
.
Before publishing to npm, test your module locally:
# In your module directory
npm link
# In your test project
npm link google-drive-uploader-js
# Test the module
node test-script.js
MIT
If you encounter any issues, please check the Google Drive API documentation or create an issue in the repository.
FAQs
A Node.js module for uploading, downloading, and managing files on Google Drive using OAuth2 authentication
The npm package google-drive-uploader-js receives a total of 7 weekly downloads. As such, google-drive-uploader-js popularity was classified as not popular.
We found that google-drive-uploader-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.