teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

修正漏れを修正

2021/01/14 11:53

投稿

ppaul
ppaul

スコア24672

answer CHANGED
@@ -1,7 +1,7 @@
1
1
  flaskやfirebaseについては使ったことがありませんが、以下で動くかもしれません。
2
2
  fileはwerkzeug.datastructures.FileStorageなのですね。
3
3
  一度bytearrayに入れて読むのを試してください。
4
- コードを修正しました。
4
+ コードを修正しました。
5
5
 
6
6
  ```python
7
7
  import io
@@ -22,7 +22,7 @@
22
22
  bstream = io.ByteIO()
23
23
  file.save(bstream)
24
24
  bstream.seek(0)
25
- blob.upload_from_file(io.BytesIO(file).read(), content_type=content_type)
25
+ blob.upload_from_file(bstream.read(), content_type=content_type)
26
26
  blob.make_public()
27
27
  return blob.public_url
28
28
  ```

1

コードを変更

2021/01/14 11:53

投稿

ppaul
ppaul

スコア24672

answer CHANGED
@@ -1,4 +1,7 @@
1
1
  flaskやfirebaseについては使ったことがありませんが、以下で動くかもしれません。
2
+ fileはwerkzeug.datastructures.FileStorageなのですね。
3
+ 一度bytearrayに入れて読むのを試してください。
4
+ コードを修正しました。
2
5
 
3
6
  ```python
4
7
  import io
@@ -16,6 +19,9 @@
16
19
  content_type = 'image/png'
17
20
  else:
18
21
  content_type = 'image/jpg'
22
+ bstream = io.ByteIO()
23
+ file.save(bstream)
24
+ bstream.seek(0)
19
25
  blob.upload_from_file(io.BytesIO(file).read(), content_type=content_type)
20
26
  blob.make_public()
21
27
  return blob.public_url