アイテム管理機能のDB設計が終わったので、次はapiを作ります
必要なapiは
- サークル作成
- サークル情報取得
- サークル情報更新
- アイテム登録
- アイテム情報取得
- アイテム情報更新
- 登録アイテム一覧
といったところでしょうか。結構ありますね。
今回はサークル周りを作ってみました。
サークルの作成と、アイコン、サークル名の変更ができます。
新しく覚えたこと
webapp2 について
multipart/form-data で受け取った画像を扱う場合(キーは'circlecut'とします)
- self.request.params["circlecut"].filename でファイル名
- self.request.params["circlecut"].type でmine type
- self.request.get('circlecut') で画像バイナリ本体
にアクセスできる
cloud storage
GAE上で CloudStorageにアクセスする場合は Google Cloud Storage Python Client Library を使う
https://developers.google.com/appengine/docs/python/googlecloudstorageclient/?hl=ja
GCSへのファイル書き込みは
circlecutBlob = self.request.get('circlecut')
circlecutType = self.request.params["circlecut"].type
circlecutHash = hashlib.md5(circlecutBlob).hexdigest()
circlecutpath = Common.createCirclecutPath(circlecutHash)
gcs_file = gcs.open(circlecutpath,
'w',
content_type=circlecutType,
options={},
retry_params=gcs.RetryParams(backoff_factor=1.1))
gcs_file.write(circlecutBlob)
gcs_file.close()
となっていて、POSTリクエスト multipart/form-data で飛んできた画像を '/freemarket/circlecut/MD5'のファイルパスで CloudStorage に保存しています。
最近のAppEngine はローカル環境用 CloudStorage というのが用意されていて、今回保存したファイルであれば devserver 起動後 http://localhost:8080/_ah/gcs/freemarket/circlecut/xxxxxx といった形でブラウザから確認できます
残タスク
- アイテム登録
- アイテム情報取得
- アイテム情報更新
- 登録アイテム一覧
今後の課題
- UIの色を変更したい
- 配送方法が不明