Skip to content

How to pass additional data with request #132

Open
@sts-ryan-holton

Description

@sts-ryan-holton

Hi, I'm using this package in my Laravel 11 project using Livewire v3. I need to pass the file along with other data I have. How can I achieve this? My top level element with x-data on it contains:

Note the createUpload function here. That's where it's happening

<section
  x-data="{
    uploader: null,
    dropping: false,
    progress: 0,
    schedule: {
      file: null,
      notes: null,
      start_processing_at: '{{ now()->addMinutes(5)->toDateTimeString() }}',
      priority: 50
    },

    cancel () {
      if (! this.uploader) {
        return
      }

      this.uploader.abort()

      $nextTick(() => {
        this.uploader = null
        this.progress = 0
      })
    },

    setDropFile (event) {
      const file = event.dataTransfer?.files[0] || event.target.files[0]

      if (! file) {
        return
      }

      this.schedule.file = file
    },

    handleUpload () {
      this.uploader = createUpload({
        file: this.schedule.file,
        endpoint: '{{ route('livewire.upload') }}',
        method: 'post',
        headers: {
          'X-CSRF-TOKEN': '{{ csrf_token() }}'
        },
        chunkSize: 2.5 * 1024
      })

      this.uploader.on('progress', (progress) => {
        this.progress = progress.detail
      })

      this.uploader.on('chunkSuccess', (response) => {
        if (! response.detail.response.body) {
            return
        }

        $wire.call('handleUploadSuccess', file.name, JSON.parse(response.detail.response.body).file)
      })

      this.uploader.on('uploadSuccess', () => {
        this.uploader = null
        this.progress = 0
      })
    }
  }"
>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions