将此文件放在一起,将文件上传到我的google云端硬盘。 我需要它能够处理一个大的.zip文件,或多个图像文件。 目前,如果您上传一个大的.zip文件(大约7MB),它就会超时
我希望让它上传多个文件。
应用脚本:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var unitNumber = form.unitNumber;
if (unitNumber == "") {
unitNumber = "";
} else {
unitNumber = " #" + unitNumber;
}
var foldertitle = form.streetAddress + unitNumber + ' ' + form.cityName + ' ' + form.stateName + ' - ' + form.businessName + ' ' + form.managerName + ' - ' + form.propertyType;
var folder, folders = DriveApp.getFolderById("0B0V8-0eo7tx8MTQzcGFwdXF6SFU");
var createfolder = folders.createFolder(foldertitle);
folder = createfolder;
var blob = form.filename;
var file = folder.createFile(blob);
return "File uploaded successfully ";
} catch (error) {
Logger.log('err: ' + error.toString());
return error.toString();
}
}
表单代码
<body>
<div id="formcontainer">
<form id="myForm">
<div>
<input type="text" name="businessName" placeholder="Business Name">
</div>
<div>
<input type="text" name="managerName" placeholder="Manager Name">
</div>
<div>
<input type="text" name="streetAddress" placeholder="Street Address">
</div>
<div>
<input type="text" name="unitNumber" placeholder="Unit Number">
</div>
<div>
<input type="text" name="cityName" placeholder="City">
</div>
<div>
<input type="text" name="stateName" placeholder="State">
</div>
<br>
<label for="propertyType">Choose Type</label>
<br>
<select name="propertyType">
<option value="Interactive Floor Plan">IFP</option>
<option value="Pictures Only">Pictures</option>
<option value="Video Only">Video</option>
<option value="Complete Property">All</option>
</select>
<br>
<label for="myFile">Compress All Files into .zip file</label>
<br>
<input type="file" name="filename" id="myFile" multiple>
<input type="submit" value="Upload File" onclick="this.value='Uploading..';
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>
<style>
body {
max-width: 400px;
padding: 20px;
margin: auto;
}
input {
display: inline-block;
width: 100%;
padding: 5px 0px 5px 5px;
margin-bottom: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
select {
margin: 5px 0px 15px 0px;
}
input[type="submit"] {
width: auto !important;
display: block !important;
}
input[type="file"] {
padding: 5px 0px 15px 0px !important;
}
</style>
</body>
答案 0 :(得分:0)
如果没有多个文件输入,我没有看到其他方法让GAS使用多个文件。您可以使用Jquery(或普通Javascript)添加dinamically输入,并在服务器端进行测试以检查传输的文件数量。
像这样: 在HTML中:
<input type="file" name="filename0" id="myFile"><div id="moreInputs"></div>
<button onClick="moreFieds()">Add more Fieds</button>
<script>
var numInputs = 1;
function moreFieds(){
$('#moreInputs').append($('<input type="file" name="filename'+numInputs+'" id="myFile">'));
numInputs++;
}
</script>
在code.gs中:
var numForms = 0;
while( form[ (filename + numForms) ] ){
var blob = form[ (filename + numForms) ];
var file = folder.createFile(blob);
numForms++;
}
或者我更喜欢,在脚本中逐个发送文件输入,为每个输入提供自己的表单,这样你就可以知道每个文件何时加载了successHandler。