Hướng dẫn tạo bbcode up file lên driver google bằng google app scrip
Forumotion có chức năng đính kèm nhưng dung lượng khá ít tầm 20MB như vậy được rất ít. Hotrofm mới tham khảo nhatchanh.info cách up lên driver google rất hay bằng app scrip. google driver tất nhiên là ngon rùi. với tài khoản free thì các bạn có 15G . bạn nào nhu cầu up nhiều file thì mua tài khoản không giới hạn dung lượng ( trên mạng bán rất nhiều từ 100>300k đều có )
Bước 1: truy cập vào https://www.google.com/script/start/ rùi click vào star strip
- Dán đoạn mã dưới đây vào file *.gs và lưu lại
Code:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var dropbox = "Student Files"; // tên thư mục trong Google Drive
var folder, folders = DriveApp.getFoldersByName(dropbox);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
var blob = form.myFile;
var file = folder.createFile(blob);
file.setDescription("Uploaded by " + form.myName);
return "File uploaded successfully " + file.getUrl();
} catch (error) {
return error.toString();
}
}
- Tiếp theo, tạo một file với tên form.html bằng cách vào menu File ~> New ~> Html file
Code:
<form id="myForm">
<input type="text" name="myName" placeholder="Your name..">
<input type="file" name="myFile">
<input type="submit" value="Upload File"
onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
input { display:block; margin: 20px; }
</style>
- Tại menu Run ~> doGet để ủy quyền cho các kịch bản. Để nó có thể tải các tập tin từ form.html lên Google Drive của bạn
- Tiếp theo, chọn Publish ~> Deploy as web app và nhấn Save New Version, cấp quyền truy cập vào ứng dụng bằng cách chọn trình đơn thả xuống (bạn có thể chọn bất cứ ai cũng có thể tải file lên Google Drive của bạn bằng cách chọn Anyone, even anonymous). Và bạn sẽ được cung cấp một địa chỉ bất cứ ai cũng có thể truy cập vào địa chỉ này để tải các tập tin lên Google Drive của bạn.
Khi chúng ta có đoạn link mầu khoanh đỏ ở trên thì copy link đó vào code sau
HTML & JAVASCRIPT>>Javascript codes management tạo 1 js
Code:
$(window).load(function() {
$('.sceditor-group:nth-child(4)').prepend('<a class="sceditor-button sceditor-button-upfilePop-hotrofm" title="Úp File"><div style="background:url(http://i.imgur.com/LLgXFFc.gif) no-repeat center;"></div></a>');
$('.sceditor-button-upfilePop-hotrofm').click(function(){
var left = ($(window).width() / 2) - (300 / 2),
top = ($(window).height() / 2) - (300 / 2),
popup = window.open("link khoanh đỏ", "popup", "width=400, height=300, top=" + top + ", left=" + left);
});
});
Tiếp đó dùng
Code:
<script src='link js vừa tạo'></script>
vào posting body và viewtopic là dc rùi :)
Bước cuối cùng
bạn vào https://drive.google.com/drive/
rùi tìm file Student Files click chuột phải vào chia sẻ
rùi để chế độ ai cũng có thể xem
Xong
Tags: #code #bbcode