Skip to content
New issue

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

local file URL #1681

Closed
zoobibackups opened this issue Sep 21, 2024 · 1 comment
Closed

local file URL #1681

zoobibackups opened this issue Sep 21, 2024 · 1 comment

Comments

@zoobibackups
Copy link

zoobibackups commented Sep 21, 2024

when I get the file from local to sign the pdf
file:///data/user/0/com.camscanner/files/react-native.pdf
this. error show
when I add this local file URL but they get error possible unhandled promise rejection Error sun.net.www.protocol.file.fileurlconnection cannot be cast to java.net.HttpURLConnection

and when I set this url = http://samples.leanpub.com/thereactnativebook-sample.pdf
this url working fine

@zoobibackups
Copy link
Author

const {uri} = route.params;
const [filePath, setFilePath] = useState(uri);
const base64ToArrayBuffer = base64 => {
const binary_string = atob(base64);
const len = binary_string.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
};

const uint8ToBase64 = u8Arr => {
const CHUNK_SIZE = 0x8000; //arbitrary number
let index = 0;
const length = u8Arr.length;
let result = '';
let slice;
while (index < length) {
slice = u8Arr.subarray(index, Math.min(index + CHUNK_SIZE, length));
result += String.fromCharCode.apply(null, slice);
index += CHUNK_SIZE;
}
return btoa(result);
};

readFile = () => {
RNFS.readFile(filePath, 'base64').then(contents => {
setPdfBase64(contents);
setPdfArrayBuffer(base64ToArrayBuffer(contents));
});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant