cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Calling FileWrite.write returns Type Error

Open canhduckhong opened this issue 1 year ago • 2 comments
trafficstars

Bug Report

Problem

I got this error when trying to write a binary string into file.

this._realReader.readAsArrayBuffer is not a function. 
(In 'this._realReader.readAsArrayBuffer(file)', 
'this._realReader.readAsArrayBuffer' is undefined)

The error is thrown at FileReader.js, line 302.

FileReader.prototype.readAsArrayBuffer = function (file) {
    if (initRead(this, file)) {
        return this._realReader.readAsArrayBuffer(file);
    }
    const totalSize = file.end - file.start;
    readSuccessCallback.bind(this)('readAsArrayBuffer', null, file.start, totalSize, function (r) {
        const resultArray = (this._progress === 0 ? new Uint8Array(totalSize) : new Uint8Array(this._result));
        resultArray.set(new Uint8Array(r), this._progress);
        this._result = resultArray.buffer;
    }.bind(this));
}; 

Here is how I call the FileWriter in my code:

writeBlobToFile = (file: FileEntry, blob): angular.IPromise<void> => {
        return this.$q((resolve, reject) => {
            file.createWriter((fileWriter) => {
                fileWriter.write(blob);
                fileWriter.onwriteend = resolve;
                fileWriter.onerror = reject;
            }, reject);
     });
};

Environment, Platform, Device

iOS 17.6 and iOS 18.0 iPhone 13 Plus

Version information

cordova-plugin-file version 8.1.0 cordova-ios version 7.1.0

canhduckhong avatar Sep 20 '24 19:09 canhduckhong