0

我将 HTMLServices 与google.script.runargs 中的表单调用一起使用,我尝试从表单输入文件字段中获取图像并将其存储在我的驱动器中。

除了 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>
4

1 回答 1

1

您使用了错误的 createFile 方法重载。

设置用户

当您应该使用createFile(blob)时,您正在使用createFile(name, content ) 。

...
var file = DriveApp.getFolderById('****************************').createFile(blob);
...

您必须定义file才能使:obj.photo = file.getUrl();.

您还可以更改以下内容:

...
<input class="myButton" onClick="onUsagerEditFormSubmit" type="button" name="save" id="save-button" value="Sauvegarder" />
...

经过:

...
<input class="myButton" onClick="onUsagerEditFormSubmit(this.parentNode)" type="button" name="save" id="save-button" value="Sauvegarder" />
...

  function onUsagerEditFormSubmit() {
    loading(true);
    var form = this.parentNode;
    google.script.run.withSuccessHandler(showUsager)
        .withFailureHandler(showError)
        .setUsager(form);    
  }

经过:

  function onUsagerEditFormSubmit(form) {
    loading(true);
    google.script.run.withSuccessHandler(showUsager)
        .withFailureHandler(showError)
        .setUsager(form);    
  }

轻微变化:

...
Logger.log(Utilities.jsonStingify(blob);
...
obj = new {};
...

经过:

...
Logger.log(Utilities.jsonStringify(blob));
...
var obj = {};
...
于 2013-08-17T20:06:27.467 回答