duancan1950 2014-06-23 06:46
浏览 60

如何使用上传到Blobstore的图像扩展数据存储示例

I spent a few days researching this and I think it's a general enough question to ask here so that it would benefit other beginners. I have few ideas how to solve it and would like guidance of a more experienced person.

the example code in https://developers.google.com/appengine/docs/go/gettingstarted/usingdatastore creates a template and redirects to "/sign" when the submit button is pressed. At "/sign", the form values are loaded into datastore and the client is redirected to "/"

the example code in https://developers.google.com/appengine/docs/go/blobstore/ creates a template and from my understanding when the submit button is pressed, the form values are loaded into blobstore and the client is redirected to "/upload"

so from my understanding, in blobstore, the writing is before redirecting to "/upload", and in datastore, the writing is after redirecting to "/sign"

So the question is how do I split writing an image to blobstore and writing info about the image to datastore when pressing submit?

The simplest solution that I thought of is on "submit" to use blobstore method and write everything to blobstore then get data with r.FromValue("info") and put it into datastore. the disadvantage is that I have a duplicate of "info" in both datastore and blobstore.

The other solution would be to "submit" the form with datastore method and then manually put the image to blobstore. The way I found to do it, which might not be optimal, is to convert the image to []byte (Golang Converting image.Image to []byte) the us blobstore.Create and writer.write([]byte) The disadvantage of this method is that image might be too big to be redirected to "/sign". This comment is my inexperienced intuition and i might be wrong.

I highly appreciate your help

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染