在 Google App Engine 上解析多部分表单
Parse multipart form on Google App Engine
我正在从事的一个项目依赖于 Google App Engine 上托管的服务从 SendGrid 解析。下面的代码是我们正在做的一个例子:
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.")
}
当 SendGrid 发布其多部分表单时,控制台显示类似于以下内容:
2018/01/04 23:44:08 ERROR: Unable to parse form: open /tmp/multipart-445139883: no file writes permitted on App Engine
App Engine 不允许您 read/write 文件,但 Golang 似乎需要它来解析。是否有特定于 App Engine 的库来解析多部分表单,或者我们应该完全使用与标准 net/http
库不同的方法?我们正在使用标准的 go 运行时。
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.
服务器试图将所有文件写入磁盘,因为应用程序 -1
作为 maxMemory
传递。使用大于您希望上传的文件大小的值。
我正在从事的一个项目依赖于 Google App Engine 上托管的服务从 SendGrid 解析。下面的代码是我们正在做的一个例子:
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.")
}
当 SendGrid 发布其多部分表单时,控制台显示类似于以下内容:
2018/01/04 23:44:08 ERROR: Unable to parse form: open /tmp/multipart-445139883: no file writes permitted on App Engine
App Engine 不允许您 read/write 文件,但 Golang 似乎需要它来解析。是否有特定于 App Engine 的库来解析多部分表单,或者我们应该完全使用与标准 net/http
库不同的方法?我们正在使用标准的 go 运行时。
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.
服务器试图将所有文件写入磁盘,因为应用程序 -1
作为 maxMemory
传递。使用大于您希望上传的文件大小的值。