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 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥15 第一个已完成,求第二个做法
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?