LoginSignup
1
3

More than 5 years have passed since last update.

(備忘)FirebaseのStorageに画像を投げる

Last updated at Posted at 2018-12-04

index.vue

<template>
  <div>
    画像:
    <img v-show="uploadedImage" :src="uploadedImage">
    <input type="file" accept="image/png,image/jpeg" v-on:change="getFile"><br>
    <button v-on:click="getFile">ストレージへアップロード</button>
  </div>
</template>

<script>
import firebase from "@/plugins/firebase";

export default {
  data() {
    return {
      uploadedImage: '',
      file: null
    }
  },
  methods: {
    uploadFileToStorage: function() {
      var storageRef = firebase.storage().ref(this.file.name);
      storageRef.put(this.file.name).then(function() {
          console.log("image uploaded");
      });
    },
    getFile: function(e) {
      const files = e.target.files || e.dataTransfer.files;
      this.file = files[0];
    }
  }
}
</script>

firebase側の設定

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

参考

1
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
1
3