doutan1857 2013-02-16 15:58
浏览 35
已采纳

在GAE Go中上传文件

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

  • 写回答

4条回答 默认 最新

  • douyun7718 2013-02-18 13:53
    关注

    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)
    

    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 )
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿