function uploadFileToDrive(file) {
const formData = new FormData();
formData.append('file', file);
fetch('https://www.googleapis.com/upload/drive/v3/files?uploadType=media', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': file.type
},
body: file
})
.then(response => response.json())
.then(data => {
console.log('File uploaded:', data);
const fileUrl = `https://drive.google.com/file/d/${data.id}/view`;
document.getElementById('file-link').innerHTML = `
File Uploaded Successfully!
Download File
Edit File
`;
})
.catch(error => {
console.error('Error uploading file:', error);
alert('Error uploading file.');
});
}
document.getElementById('upload-button').addEventListener('click', function() {
const fileInput = document.getElementById('file-input');
const file = fileInput.files[0];
if (file) {
uploadFileToDrive(file);
} else {
alert('Please select a file to upload.');
}
});
Comments
Post a Comment