tus-js-client: Crashed to upload large files ( > 500MB): [Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer']

Hi.

I’m trying to upload a large file. My application crashes after launching the upload with the error:

  • Terminating app due to uncaught exception ‘NSMallocException’, reason: ‘Failed to grow buffer’

On a small file size works well.

iPad Pro Deployment Target : 12.1 React-Native v0.58

Code:

      const upload = new tus.Upload({ uri: 
        `${RNFS.DocumentDirectoryPath}/images/${item.image}`}, {
        endpoint: 'http://192.168.1.5:1080/files/',
        retryDelays: [0, 1000, 3000, 5000, 10000, 15000, 20000],
        resume: true,
        metadata: {
          name: item.image,
          filetype: item.image.substring(item.image.lastIndexOf('.') + 1).toUpperCase(),
          copyright: 30
        },
        onError: (error) => {
          console.log('Error upload:', error)
        },
        onProgress: (uploadedBytes, totalBytes) => {
          console.log(`Progress: ${uploadedBytes / totalBytes}%`)
        },
        onSuccess: () => {
          console.log('Upload URL:', upload.url)
        }
      })
      upload.start()

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 55 (19 by maintainers)

Most upvoted comments

@nikolaytsigvintsev I managed to upload it to Vimeo with large files. Implementation:

_upload = new Upload(file, {
      uploadUrl: video.url,
      retryDelays: [0, 1000, 3000, 5000],
      chunkSize: 15 * 1024 * 1024,
      fileReader: new TusFileReader(),
      uploadSize: video.size,
      metadata: {
        filename: video.name || video.filename,
        filetype: video.mime
      },
      onError: (error) => onError(video.hashId, error),
      onProgress: (bytesAccepted, bytesTotal) => onProgress(video.hashId, bytesAccepted, bytesTotal),
      onSuccess: () => onSuccess(video.hashId)
    });

    _upload.start();

import RNFS from 'react-native-fs'
import base64 from 'base64-js'

export default class TusFileReader {
  openFile(input, chunkSize){
    return RNFS.stat(input.uri)
     .then((stats) => new FileSource(input, stats.size))
     .catch((err) => console.tron.log('erro', err))
  }
}

class FileSource {
  constructor(file, size){
    this._file = file
    this._size = size
  }

  async slice(start, end){
    end = Math.min(end, this._size)
    const length = end - start;
    const position = start;

    const data = await RNFS.read(this._file.uri, length, position, 'base64')
    const value = base64.toByteArray(data)

    return Promise.resolve({ value });
  }

  close(){}
}

sources:

if you want to use tus-js-client you need to have a tus compatible backend. the official recommended one is https://github.com/tus/tusd

did you try this code? #146 (comment)

i will try it with a compatible backend

if you want to use tus-js-client you need to have a tus compatible backend. the official recommended one is https://github.com/tus/tusd

did you try this code? https://github.com/tus/tus-js-client/issues/146#issuecomment-671967166

@samal-rasmussen Ah, thank you for the insights. So if I understand correctly, you are just using the FileReader that is built into tus-js-client? I.e. this one: https://github.com/tus/tus-js-client/blob/c0b5a7dec0f084db8e6c2e75eae25a19a2e364d3/lib/browser/fileReader.js#L9-L19