🐥

wip【音声ファイルアップロード機能】storeの値をformdataに設定したい

2021/08/01に公開
    async uploadMusicFile () {
      let formData = new FormData();

      formData.append('music_file', this.musicFile);
      formData.append('cover_image', this.coverImages[0]);
      formData.append('title', this.musicFileName);
      formData.append('genre', this.genre);
      formData.append('emotions', this.emotion);
      formData.append('user_id', 'ここ'); //後にauthのidをセットする

      let config = {
        headers: {
            'content-type': 'multipart/form-data',
            // 'Access-Control-Allow-Origin': '*',
            // 'Access-Control-Allow-Headers': '*',
            'contentType': false,
            'processData': false
        },
      };

      await this.$axios.post('api/musicFileUpload', formData, config)
      .then(res => {
        console.log(res)
        this.posts = res.data.posts
        console.log(this.posts)
        this.closeAfterMusicUploadModal()
        location.reload();
      })
      .catch(err => {
        console.log(err)
      })
    },

これでいけた

      formData.append('music_file', this.musicFile);
      formData.append('cover_image', this.coverImages[0]);
      formData.append('title', this.musicFileName);
      formData.append('genre', this.genre);
      formData.append('emotions', this.emotion);
      formData.append('user_id', this.$store.state.auth.user.id);
      formData.append('user_name', this.$store.state.auth.user.name);

Discussion