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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据