LoginSignup
1
1

More than 3 years have passed since last update.

(gas) doPostで「現在、ファイルを開くことができません。」というレスポンスが返り処理が失敗する

Posted at

doPostで「現在、ファイルを開くことができません。」というレスポンスが返ってくる

GasのWebアプリをデプロイしたときに、doPostの処理を下記のように実装していたところ、


function doPost(e) {
  //do something
  //{ok:true} を返す。
  return ContentService.createTextOutput(JSON.stringify({ok:true}, null, 2))
          .setMimeType(ContentService.MimeType.JSON);
} 

レスポンスが下記のようになってしまう現象がありました。
(さらに、doPostの処理自体も実行されませんでした。)

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta name="description" content="ウェブ ワープロ、プレゼンテーション、スプレッドシート">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <link rel="shortcut icon" href="//docs.google.com/favicon.ico">
    <title>ページが見つかりません</title>
    <meta name="referrer" content="origin">
    <link href="//fonts.googleapis.com/css?family=Product+Sans" rel="stylesheet" type="text/css" nonce="dyW2qxOghsguMpKStDe2JA">
    <style nonce="dyW2qxOghsguMpKStDe2JA">/* Copyright 2021 Google Inc. All Rights Reserved. */
.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}#drive-logo{margin:18px 0;position:absolute;white-space:nowrap}.docs-drivelogo-img{background-image:url('//ssl.gstatic.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png');background-size:116px 41px;display:inline-block;height:41px;vertical-align:bottom;width:116px}.docs-drivelogo-text{color:#000;display:inline-block;opacity:0.54;text-decoration:none;font-family:'Product Sans',Arial,Helvetica,sans-serif;font-size:32px;text-rendering:optimizeLegibility;position:relative;top:-6px;left:-7px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}@media (-webkit-min-device-pixel-ratio:1.5),(min-resolution:144dpi){.docs-drivelogo-img{background-image:url('//ssl.gstatic.com/images/branding/googlelogo/2x/googlelogo_color_116x41dp.png')}}</style><style type="text/css" nonce="dyW2qxOghsguMpKStDe2JA">body {background-color: #fff; font-family: Arial,sans-serif; font-size: 13px; margin: 0; padding: 0;}a, a:link, a:visited {color: #112ABB;}</style><style type="text/css" nonce="dyW2qxOghsguMpKStDe2JA">.errorMessage {font-size: 12pt; font-weight: bold; line-height: 150%;}
    </style>
  </head>
  <body>
    <div id="outerContainer">
      <div id="innerContainer">
        <div style="position: absolute; top: -80px;">
          <div id="drive-logo">
            <a href="/">
              <span class="docs-drivelogo-img" title="Google ロゴ"></span>
              <span class="docs-drivelogo-text">&nbsp;ドライブ</span>
            </a>
          </div>
        </div>
        <div align="center">
          <p class="errorMessage" style="padding-top: 50px">現在、ファイルを開くことができません。</p>
          <p>アドレスを確認して、もう一度試してください。</p>
          <div style="background: #F0F6FF; border: 1px solid black; margin-top: 35px; padding: 10px 125px; width: 300px;">
            <p><strong>あれもこれも Google ドライブで</strong></p>
            <p> Google ドライブにはドキュメント やスプレッドシート、プレゼンテーションなどを簡単に作成、保存してオンラインで共有できるアプリが揃っています。</p><p>詳細 は<a href="https://drive.google.com/start/apps">drive.google.com/start/apps</a>をご覧ください。</p></div></div></div></div></body><style nonce="dyW2qxOghsguMpKStDe2JA">html {height: 100%; overflow: auto;}body {height: 100%; overflow: auto;}#outerContainer * Connection #1 to host script.googleusercontent.com left intact
{margin: auto; max-width: 750px;}#innerContainer {margin-bottom: 20px; margin-left: 40px; margin-right: 40px; margin-top: 80px; position: relative;}</style></html>

原因:doPostで ContentService.createTextOutput を返り値にしていたためだった

doGetで使用できていたため、doPostでもContentService.createTextOutput で結果をjsonとして返そうとしたところ失敗しました。

解決方:doPostは値を返さないようにする。


function doPost(e) {
  // do something
  // 値を返す処理をしない
} 

これでdoPostの処理が成功するようになりました。
以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1