Reputation: 31
As title, I am currently working on an uploading page which enables users to upload the files(jpg and Doc) to the folder on Google Drive. However, the problems seem to be that although the files are uploaded successfully, I am not able to open them, and the size of the files is bigger in comparison to the original one. Below is what I currently have, please let me know if this can get any further.
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('index.html');
}
function uploadFiles(form) {
try {
var dropbox = "1 作文上傳";
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("上傳者: " + form.Name + " 電話: "+ form.Phone + " 信箱: " + form.Email);
return "<h2>雲端上傳系統</h2><input type='submit' value='上傳完成,可關閉視窗' onclick='window.close();'></form></div>";
} catch (error) {
return error.toString();
}
}
html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>雲端上傳系統</title>
</head>
<body>
<div id="myForm">
<form method="post">
<h2>雲端上傳系統</h2>
<input type="text" name="Name" placeholder="請輸入姓名"><br/>
<input type="text" name="Phone" placeholder="請輸入你的電話"><br/>
<input type="text" name="Email" placeholder="請輸入你的信箱"><br/>
<input type="file" name="myFile">
<input type="submit" value="上傳檔案"
onclick="this.value='檔案上傳中……';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
</div>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
</body>
</html>
Upvotes: 0
Views: 97
Reputation: 792
I had the same problem and it came that the new version of GAS has a bug when creating a file with var file = folder.createFile(blob);
Try to disbale the GAS V8 and use legacy.
Upvotes: 1