textileio / js-textile

Textile's JavaScript Libs. Home of ThreadDB, Buckets, and more. Available on npm as `@textile/hub`.
https://textileio.github.io/js-textile/docs
MIT License
85 stars 19 forks source link

buckets pushPath intermittent error 'parsing event in validate write' #1212

Closed tomjohnhall closed 2 years ago

tomjohnhall commented 2 years ago

Buckets pushPath sometimes throws this error:

Error: parsing event in validate write: SyntaxError: (anonymous): Line 1:339 Unexpected identifier (and 2 more errors)

It seems to happen on some jpg files, but I haven't yet been able to see any pattern in the files that fail.

Here's how I'm generating the buffer, basically identical to the docs:

        const reader = new FileReader()
        reader.onabort = () => reject('file reading was aborted')
        reader.onerror = () => reject('file reading has failed')
        reader.onload = async () => {
          const binaryStr = reader.result
          if (binaryStr) {
            if (audio) {
              const duration = await this.getDuration(file)
              uploadData(binaryStr, duration)
            }
            else uploadData(binaryStr)
          }
        }
        reader.readAsArrayBuffer(file)

Where uploadData eventually calls buckets.pushPath(this.bucketKey, path, data)

Anyone come across this or could point to where it might be originating?

Thanks!

tomjohnhall commented 2 years ago

Ah, doh! This is due to attempting to write files to paths with characters such as ' in the filename. Once I strip everything to alphanumeric, they work fine!