We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here's the code in case someone wants to read files that start with content:// on Android:
content://
import RNFS from "react-native-fs"; import { Base64 } from "js-base64"; import fileType from "file-type"; import RNFetchBlob from "rn-fetch-blob"; import { Platform } from "react-native"; function min(a, b) { return a < b ? a : b; } function FileType(path) { return new Promise((resolve, reject) => { if (Platform.OS === "ios") { RNFS.stat(path) .then((statResult) => { const numberBytes = min(statResult.size, 64); RNFS.read(path, numberBytes, 0, "base64").then((fileData) => { let convertedData = CovertBase64ToArrayBuffer(fileData); convertedData = new Uint8Array(convertedData); let type = fileType(convertedData); if (type === undefined || type === null) { let decodedData = String.fromCharCode.apply(null, convertedData); if (decodedData.startsWith("<html>") || decodedData.endsWith("</html>")) { type = { ext: "html", mime: "text/html" }; } } resolve(type); }); }) .catch((reason) => { reject(reason); }); } else { RNFetchBlob.fs .stat(path) .then((file) => { const numberBytes = min(file.size, 64); RNFetchBlob.fs.readFile(path, "base64", numberBytes).then((fileData) => { let convertedData = CovertBase64ToArrayBuffer(fileData); convertedData = new Uint8Array(convertedData); let type = fileType(convertedData); if (type === undefined || type === null) { let decodedData = String.fromCharCode.apply(null, convertedData); if (decodedData.startsWith("<html>") || decodedData.endsWith("</html>")) { type = { ext: "html", mime: "text/html" }; } } resolve(type); }); }) .catch((reason) => { reject(reason); }); } }); } function CovertBase64ToArrayBuffer(data) { let UTF8Data = Base64.atob(data); let UTF8DataLength = UTF8Data.length; let bytes = new Uint8Array(UTF8DataLength); for (var i = 0; i < UTF8DataLength; i++) { bytes[i] = UTF8Data.charCodeAt(i); } return bytes.buffer; } export default FileType;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Here's the code in case someone wants to read files that start with
content://
on Android:The text was updated successfully, but these errors were encountered: