Sha256: 746f80a6df35b8ebf5aeb0f3981571936513f15438cdb51d52d61c1929e50269

Contents?: true

Size: 911 Bytes

Versions: 193

Compression:

Stored size: 911 Bytes

Contents

export class BlobUpload {
  constructor(blob) {
    this.blob = blob
    this.file = blob.file

    const { url, headers } = blob.directUploadData

    this.xhr = new XMLHttpRequest
    this.xhr.open("PUT", url, true)
    this.xhr.responseType = "text"
    for (const key in headers) {
      this.xhr.setRequestHeader(key, headers[key])
    }
    this.xhr.addEventListener("load", event => this.requestDidLoad(event))
    this.xhr.addEventListener("error", event => this.requestDidError(event))
  }

  create(callback) {
    this.callback = callback
    this.xhr.send(this.file.slice())
  }

  requestDidLoad(event) {
    const { status, response } = this.xhr
    if (status >= 200 && status < 300) {
      this.callback(null, response)
    } else {
      this.requestDidError(event)
    }
  }

  requestDidError(event) {
    this.callback(`Error storing "${this.file.name}". Status: ${this.xhr.status}`)
  }
}

Version data entries

193 entries across 188 versions & 18 rubygems

Version Path
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/app/javascript/activestorage/blob_upload.js
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/app/javascript/activestorage/blob_upload.js
activestorage-7.0.5 app/javascript/activestorage/blob_upload.js
activestorage-7.0.4.3 app/javascript/activestorage/blob_upload.js
activestorage-6.1.7.3 app/javascript/activestorage/blob_upload.js
activestorage-6.1.7.2 app/javascript/activestorage/blob_upload.js
activestorage-7.0.4.2 app/javascript/activestorage/blob_upload.js
activestorage-7.0.4.1 app/javascript/activestorage/blob_upload.js
activestorage-6.1.7.1 app/javascript/activestorage/blob_upload.js
activestorage-6.0.6.1 app/javascript/activestorage/blob_upload.js
decidim-0.27.1 packages/core/node_modules/@rails/activestorage/src/blob_upload.js
decidim-0.26.4 packages/core/node_modules/@rails/activestorage/src/blob_upload.js
decidim-0.27.0 packages/core/node_modules/@rails/activestorage/src/blob_upload.js
decidim-0.26.3 packages/core/node_modules/@rails/activestorage/src/blob_upload.js
decidim-0.27.0.rc2 packages/core/node_modules/@rails/activestorage/src/blob_upload.js
activestorage-7.0.4 app/javascript/activestorage/blob_upload.js
activestorage-6.1.7 app/javascript/activestorage/blob_upload.js
activestorage-6.0.6 app/javascript/activestorage/blob_upload.js
activestorage-7.0.3.1 app/javascript/activestorage/blob_upload.js
activestorage-6.1.6.1 app/javascript/activestorage/blob_upload.js