3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

即売会サービスを作ろう3

Posted at

アイテム管理機能のDB設計が終わったので、次はapiを作ります
必要なapiは

  1. サークル作成
  2. サークル情報取得
  3. サークル情報更新
  4. アイテム登録
  5. アイテム情報取得
  6. アイテム情報更新
  7. 登録アイテム一覧

といったところでしょうか。結構ありますね。

今回はサークル周りを作ってみました。
サークルの作成と、アイコン、サークル名の変更ができます。

新しく覚えたこと

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へのファイル書き込みは

controller/user/api/circle.py
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 といった形でブラウザから確認できます

残タスク

  1. アイテム登録
  2. アイテム情報取得
  3. アイテム情報更新
  4. 登録アイテム一覧

今後の課題

  • UIの色を変更したい
  • 配送方法が不明
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?