设置GraphQL的最大文件上传大小(使用Golang)

huangapple go评论71阅读模式
英文:

set graphql's max file upload size (golang)

问题

我用golang编写了一个服务器,可以使用multipart form上传文件。我想扩展最大上传大小。

在我使用的实现的文档网站上,我找到了以下信息:

  • uploadMaxSize
    此选项指定用于解析请求体作为multipart/form-data的最大字节数。

  • uploadMaxMemory
    此选项指定用于在内存中解析请求体作为multipart/form-data的最大字节数,其余部分存储在临时文件中。

(这里是链接:https://github.com/99designs/gqlgen/blob/master/docs/content/reference/file-upload.md#Configuration)

这个配置可以在哪里应用?

谢谢。

英文:

I wrote an server in golang which to which files can be uploaded using multipart form. I want to extend the maximum upload size.

On the documentation site of the implementation I'm using I found following:

  • uploadMaxSize
    This option specifies the maximum number of bytes used to parse a request body as multipart/form-data.

  • uploadMaxMemory
    This option specifies the maximum number of bytes used to parse a request body as multipart/form-data in memory, with the remainder stored on disk in temporary files.

(here: https://github.com/99designs/gqlgen/blob/master/docs/content/reference/file-upload.md#Configuration)

Where can this configuration be applied?

Thanks

答案1

得分: 3

你可以在你的GraphQL处理程序中应用这些配置选项,如下所示:

var mb int64 = 1 << 20
uploadMaxMemory := handler.UploadMaxMemory(32 * mb)
uploadMaxSize := handler.UploadMaxSize(50 * mb)

http.Handle("/query", handler.GraphQL(exec, uploadMaxMemory, uploadMaxSize))
英文:

You can apply these configuration options in your GraphQL handler, like:

var mb int64 = 1 &lt;&lt; 20
	uploadMaxMemory := handler.UploadMaxMemory(32 * mb)
	uploadMaxSize := handler.UploadMaxSize(50 * mb)

	http.Handle(&quot;/query&quot;, handler.GraphQL(exec, uploadMaxMemory, uploadMaxSize))

huangapple
  • 本文由 发表于 2023年3月6日 08:08:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75646152.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定