ruby-on-railsshrineuppy

Uncaught TypeError: Cannot read property '1' of null?


I'm getting an error: Uncaught TypeError: Cannot read property '1' of null. What does this mean? The source of the error is the line that says id: file.meta['key'].match(/^cache\/(.+)/)[1]:

uppy.on('upload-success', (file, response) => {
 // construct uploaded file data in the format that Shrine expects
 const uploadedFileData = {
  id: file.meta['key'].match(/^cache\/(.+)/)[1], // object key without prefix
  storage: 'cache',
  metadata: {
   size: file.size,
   filename: file.name,
   mime_type: file.type,
  }
 }

 // set hidden field value to the uploaded file data so that it's submitted
 // with the form as the attachment
 hiddenInput.value = JSON.stringify(uploadedFileData)
})

I think this is trying to select something at an index that doesn't exist, but then...what index does exist?


Solution

  • The issue was that this id: file.meta['key'].match(/^cache\/(.+)/)[1] did not match the prefix in Shrine.storage. My prefix was uploads/cache. I just had to change it back to cache.