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

質問編集履歴

4

文章の修正

2021/02/13 09:06

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
@@ -39,4 +39,9 @@
39
39
  ```
40
40
 
41
41
  明確な原因が分からず、行き詰まっております。
42
- 何卒、お力添えをお願いいたします。
42
+ 何卒、お力添えをお願いいたします。
43
+
44
+ **追記:**
45
+ フォルダ内に画像ファイルが1つの場合、削除することができました。
46
+ 複数ある場合にエラーが出るようです。
47
+ フォルダ内に複数ある場合、どのようにすれば良いかご回答いただけると嬉しいです。

3

書式の改善

2021/02/13 09:06

投稿

ug_o
ug_o

スコア39

title CHANGED
@@ -1,1 +1,1 @@
1
- 【Firebase Storage】Promise扱いについて
1
+ 【Firebase Storage】画像削除でエラーが発生する
body CHANGED
@@ -6,27 +6,37 @@
6
6
  ### 発生している問題・エラーメッセージ
7
7
 
8
8
  ```
9
- Promise {<pending>}
10
- __proto__: Promise
11
- [[PromiseState]]: "fulfilled"
12
- [[PromiseResult]]: Object
13
- items: Array(2)
14
- 0: Reference
15
- location: Location
16
- bucket: "*****"
17
- path_: "images/profile/******/****.jpg"
18
- isRoot: (...)
19
- path: (...)
20
- __proto__: Object
9
+ FirebaseStorageError {code_: "storage/unknown", message_: "Firebase Storage: An unknown error occurred, please check the error payload for server response.", serverResponse_: "{↵ "error": {↵ "code": 400,↵ "message": "Th…d with '/' or contain two consecutive '/'s"↵ }↵}", name_: "FirebaseError"}
21
10
  ```
11
+ ```
12
+
13
+ index.esm.js?2e66:635 DELETE
14
+ https://firebasestorage.googleapis.com/v0/b/[project名].appspot.com/o/images%2Fprofile%2F[uid]%2F7poS5YqHLZcXXPqHNF2m.jpg
15
+ %2Cgs%3A%2F%2F[project名].appspot.com%2Fimages%2Fprofile%2F[uid]%2F9J6YqM11OJOI3EtIMRMO.jpg
16
+ %2Cgs%3A%2F%2F[project名].appspot.com%2Fimages%2Fprofile%2F[uid]%2F7poS5YqHLZcXXPqHNF2m.jpg
17
+ %2Cgs%3A%2F%2F[project名].appspot.com%2Fimages%2Fprofile%2F[uid]%2F9J6YqM11OJOI3EtIMRMO.jpg 400
18
+ ```
19
+
22
20
  consoleで確認するとファイルの取得自体はできているようです。
23
- pathを格納して.delete()で削除したいのですがようにすれば良いでょうか
21
+ .delete()で削除したいのですが、上記エラーが発生ています
24
22
 
25
23
  ### 該当のソースコード
26
24
 
27
25
  ```Javascript
28
26
  // Storageの削除
27
+ const imageRef = [];
29
28
  const ref = storage.ref();
30
- const profileRef = ref.child(`/images/profile/${user.uid}/`).listAll();
29
+ const profileRef = ref.child(`/images/profile/${user.uid}/`).listAll()
30
+ .then((res) => {
31
+ res.items.forEach((itemRef) => {
32
+ imageRef.push(res.items);
31
- console.log(profileRef);
33
+ console.log(imageRef);
34
+ });
35
+ })
36
+ .then(() => {
37
+ storage.refFromURL(`${imageRef}`).delete();
38
+ });
32
- ```
39
+ ```
40
+
41
+ 明確な原因が分からず、行き詰まっております。
42
+ 何卒、お力添えをお願いいたします。

2

タイトルの変更

2021/02/13 08:32

投稿

ug_o
ug_o

スコア39

title CHANGED
@@ -1,1 +1,1 @@
1
- 【Firebase Storage】特定フォルダ内ファイルを削除した
1
+ 【Firebase Storage】Promiseについて
body CHANGED
@@ -1,26 +1,32 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- Firebase Storageの特定フォルダ内のファイルを削除しす。
3
+ Firebase Storageの特定フォルダ内のファイルを削除しようとしてす。
4
- Storageの階層は下記のようになります。
5
- jpgファイル名はアップロード時にランダム変数でセットしています。
6
- ```
7
- imges/profile/[uid]/***.jpg
4
+ [.listAll()](https://firebase.google.com/docs/storage/web/list-files?hl=ja)でファイルを取得しています。
8
- ```
9
5
 
10
- 現状、ファイル名の取得ができていないので、取得方法を知りたいです。
11
- ご教授いただけますと幸いです。
12
-
13
6
  ### 発生している問題・エラーメッセージ
14
7
 
15
8
  ```
16
- FirebaseStorageError {code_: "storage/object-not-found", message_: "Firebase Storage: Object 'images/profile/[uid]/""' does not exist.", serverResponse_: "{↵ "error": {↵ "code": 404,↵ "message": "No…lete object",↵ "status": "DELETE_OBJECT"↵ }↵}", name_: "FirebaseError"}
9
+ Promise {<pending>}
10
+ __proto__: Promise
11
+ [[PromiseState]]: "fulfilled"
12
+ [[PromiseResult]]: Object
13
+ items: Array(2)
14
+ 0: Reference
15
+ location: Location
16
+ bucket: "*****"
17
+ path_: "images/profile/******/****.jpg"
18
+ isRoot: (...)
19
+ path: (...)
20
+ __proto__: Object
17
21
  ```
22
+ consoleで確認するとファイルの取得自体はできているようです。
18
- ファイル名が取得できいないめ、このエラーになってると思うのですがファイル名取得方法がわりません
23
+ pathを格納し.delete()で削除したいのですがようにすれば良いでしょうか。
24
+
19
25
  ### 該当のソースコード
20
26
 
21
27
  ```Javascript
22
- const user = getCurrentUser();
23
28
  // Storageの削除
24
29
  const ref = storage.ref();
25
- ref.child(`images/profile/${user.uid}/`).delete();
30
+ const profileRef = ref.child(`/images/profile/${user.uid}/`).listAll();
31
+ console.log(profileRef);
26
32
  ```

1

エラーコードの追加

2021/02/10 09:07

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,7 @@
13
13
  ### 発生している問題・エラーメッセージ
14
14
 
15
15
  ```
16
- FirebaseStorageError {code_: "storage/object-not-found", message_: "Firebase Storage: Object 'images/profile/[uid]'
16
+ FirebaseStorageError {code_: "storage/object-not-found", message_: "Firebase Storage: Object 'images/profile/[uid]/""' does not exist.", serverResponse_: "{↵ "error": {↵ "code": 404,↵ "message": "No…lete object",↵ "status": "DELETE_OBJECT"↵ }↵}", name_: "FirebaseError"}
17
17
  ```
18
18
  ファイル名が取得できていないため、このエラーになっていると思うのですがファイル名の取得方法がわかりません。
19
19
  ### 該当のソースコード