duanhan8757 2018-01-04 23:51
浏览 52
已采纳

在Google App Engine上解析多部分表单

A project I'm working on depends on having a service hosted on Google App Engine parse from SendGrid. The following code is an example of what we're doing:

package sendgrid_failure

import (
    "net/http"
    "fmt"
    "google.golang.org/appengine"
    "google.golang.org/appengine/log"
)

func init() {
    http.HandleFunc("/sendgrid/parse", sendGridHandler)
}

func sendGridHandler(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
    err := r.ParseMultipartForm(-1)
    if err != nil {
        log.Errorf(ctx, "Unable to parse form: %v", err)
    }

    fmt.Fprint(w, "Test.")
}

When SendGrid POSTs its multipart form, the console shows similar to the following:

2018/01/04 23:44:08 ERROR: Unable to parse form: open /tmp/multipart-445139883: no file writes permitted on App Engine

App Engine doesn't allow you to read/write files, but Golang appears to need it to parse. Is there an App Engine specific library to parse multipart forms, or should we be using a different method from the standard net/http library entirely? We're using the standard go runtime.

  • 写回答

1条回答 默认 最新

  • dongmei2956 2018-01-05 00:28
    关注

    The documentation for ParseMultipartForm says:

    The whole request body is parsed and up to a total of maxMemory bytes of its file parts are stored in memory, with the remainder stored on disk in temporary files.

    The server attempts to write all files to disk because the application passed -1 as maxMemory. Use a value larger than the size of the files you expect to upload.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测