我将 HTMLServices 与google.script.run
args 中的表单调用一起使用,我尝试从表单输入文件字段中获取图像并将其存储在我的驱动器中。
除了 photodata 字段,我正确地获得了所有字段的值。
photodata
包含字符串“FileUpload”而不是 blob。
我已经测试.getBlob
了相同的结果。
服务器端 :
function setUsager(form) {
var blob = form.photodata;
Logger.log(Utilities.jsonStingify(blob);
DriveApp.getFolderById('0B2DdOMvW2Q84N0s4a21LM05wbms').createFile(form.usagerId,blob);
obj = new {};
obj.photo = file.getUrl();
return obj;
}
点击处理程序
function onUsagerEditFormSubmit() {
loading(true);
var form = this.parentNode;
google.script.run.withSuccessHandler(showUsager)
.withFailureHandler(showError)
.setUsager(form);
}
和形式:
<form name="usager-edit" id="usager-edit" method='post' enctype="multipart/form-data">
<div class="hidden">
<input type="text" name="type" id="type" value="USAGER" readonly="readonly" />
<input type="text" name="usagerId" id="usagerId" readonly="readonly" />
</div>
<div class="field-container">
<label for="nom">Nom</label>
<input type="text" name="nom" id="nom">
</div>
<div class="field-container">
<label for="prenom">Prenom</label>
<input type="text" name="prenom" id="prenom">
</div>
<div class="field-container">
<label for="photo">Photo</label>
<input class="file" type="file" name="photodata" id="photodata" accept='image/*'>
<div id="prev-photo" name="prev-photo"></div>
<div class="clear"></div>
</div>
<input class="myButton" onClick="onUsagerEditFormSubmit" type="button" name="save" id="save-button" value="Sauvegarder" />
</form>