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条)

报告相同问题?