var self = this; var image = new FormData(ReactDOM.findDOMNode(this.refs.uploadImgForm)).get('image'); if (!(image.size <= MAX_IMAGE_SIZE)) { return alert('The file size cannot exceed 1m.'); var type = 'data:' + image.type + ';base64,'; util.readFileAsBase64(image, function(base64) { ReactDOM.findDOMNode(self.refs.uploadImg).value = ''; self.refs.textDialog.show(type + base64, base64, image.name); }); },
/** * check file existence * @param {File} file https://googleapis.dev/nodejs/storage/latest/File.html */ async function isFileExists(file) { // check file exists const res = await file.exists(); return res[0]; }
// TODO: Differenciate between input types /** * Generate a fingerprint for a file which will be used the store the endpoint * * @param {File} file * @param {Object} options * @param {Function} callback */ export default function fingerprint(file, options) { if (isReactNative()) { return Promise.resolve(reactNativeFingerprint(file, options)); } return Promise.resolve([ "tus-br", file.name, file.type, file.size, file.lastModified, options.endpoint ].join("-")); }
const content = file.slice(0, Math.min(blockSize, file.length)); const hash = createHash("md5").update(content).digest("hex"); const fingerprint = ["node-buffer", hash, file.length, options.endpoint].join("-"); return Promise.resolve(fingerprint); if (file instanceof fs.ReadStream && file.path != null) { return new Promise((resolve, reject) => { const name = path.resolve(file.path); fs.stat(file.path, (err, info) => { if (err) { return reject(err);
/** * Is this file's path included in this collection's excludePaths. * @param {File} file File object. * @return {boolean} true if the file's path includes an exclude path. * @private */ _isFileExcluded(file) { return this.excludePaths.some(path => file.path.includes(path)); }
readSuccessCallback.bind(this)('readAsBinaryString', null, file.start, totalSize, function (r) { if (this._progress === 0) { this._result = ''; } this._result += r; }.bind(this));
/** * Checks to see if this file passes all requirements to be considered a part * of this collection. * @param {File} file File object. * @return {boolean} true if the file meets all requirements. */ _isFileInCollection(file) { return file.path.includes(this.path) && !this._isFileExcluded(file) && !this.isFiltered(file); }
/** * Checks to see if this file passes all requirements to be considered a part * of this collection. * @param {File} file File object. * @return {boolean} true if the file meets all requirements. */ _isFileInCollection(file) { return !(0, _isUndefined3.default)(file.data[this.metadata]) && !this.isFiltered(file); }
readSuccessCallback.bind(this)('readAsDataURL', null, file.start, totalSize, function (r) { var commaIndex = r.indexOf(','); if (this._progress === 0) { this._result = r; } else { this._result += r.substring(commaIndex + 1); } }.bind(this));
readSuccessCallback.bind(this)('readAsArrayBuffer', null, file.start, totalSize, function (r) { var resultArray = (this._progress === 0 ? new Uint8Array(totalSize) : new Uint8Array(this._result)); resultArray.set(new Uint8Array(r), this._progress); this._result = resultArray.buffer; }.bind(this));
readSuccessCallback.bind(this)('readAsBinaryString', null, file.start, totalSize, function (r) { if (this._progress === 0) { this._result = ''; } this._result += r; }.bind(this));
readSuccessCallback.bind(this)('readAsText', enc, file.start, totalSize, function (r) { if (this._progress === 0) { this._result = ''; } this._result += r; }.bind(this));
/** * Is this file's path included in this collection's excludePaths. * @param {File} file File object. * @return {boolean} true if the file's path includes an exclude path. * @private */ _isFileExcluded(file) { return this.excludePaths.some(path => file.path.includes(path)); }