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

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

问题描述

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

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()?

推荐答案

我设法通过使用中间返回参数other来解决我的问题。这些代码在上传处理程序中

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天全站免登陆