在 GAE Go 中上传文件 [英] Upload file in GAE Go

查看:10
本文介绍了在 GAE Go 中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 GAE 应用中上传文件.如何使用 Go 和使用 r.FormValue() 在 Google App Engine 中上传文件?

I am trying to upload a file in my GAE app. How do I the upload of a file in Google App Engine using Go and using the r.FormValue()?

推荐答案

我设法通过使用中间返回参数其他"来解决我的问题.下面的这些代码在上传处理程序中

I managed to solve my problem by using the middle return param, "other". These code below are inside the upload handler

blobs, other, err := blobstore.ParseUpload(r)

然后分配对应的formkey

Then assign corresponding formkey

file := blobs["file"]
**name := other["name"]** //name is a form field
**description := other["description"]** //descriptionis a form field

并在我的结构值赋值中像这样使用它

And use it like this in my struct value assignment

newData := data{
  Name: **string(name[0])**,
  Description: **string(description[0])**,
  Image: string(file[0].BlobKey),          
}

datastore.Put(c, datastore.NewIncompleteKey(c, "data", nil), &newData )

不是 100% 确定这是正确的,但这解决了我的问题,它现在正在将图像上传到 blobstore 并将其他数据和 blobkey 保存到数据存储区.

Not 100% sure this is the right thing but this solves my problem and it is now uploading the image to blobstore and saving other data and blobkey to datastore.

希望这也可以帮助其他人.

Hope this could help others too.

这篇关于在 GAE Go 中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆