在 Expo React Native 中下载 Base64 二维码
Download Base64 Qr Code in Expo React Native
我正在创建生成二维码的 expo react 本机应用程序。当用户单击保存按钮时生成后,我想将二维码保存在 phone 中。我尝试了这段代码,但它给出了预期的 URL 方案 'http' 或 'https' 但 'data'
下面是我的代码
downloadFile(){
const uri = "data:image/pdf;base64"+base64_qr
let fileUri = FileSystem.documentDirectory + "QRCode.pdf";
FileSystem.downloadAsync(uri, fileUri)
.then(({ uri }) => {
this.saveFile(uri);
})
.catch(error => {
console.error(error);
})
}
saveFile = async (fileUri) => {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === "granted") {
const asset = await MediaLibrary.createAssetAsync(fileUri)
await MediaLibrary.createAlbumAsync("Download", asset, false)
}
}
有人可以帮助我吗?
async downloadFile(){
try {
let filePath = await Print.printToFileAsync({
html:' <div style = "margin-top: 40%; margin-left: 30%;"><h2 style = "margin-left: 50px; font-size: 45px;">LetMeIn</h2>'
+'<img src="' + base64_qr +'"'
+ 'alt="Red dot" style = "margin-left: 20px; margin-top: 10px;" />'
+ '<h2 style = "margin-top: 50px;">Scan the QR Code to check in</h2>'
+ '</div>',
width : 612,
height : 792,
});
const pdfName = `${filePath.uri.slice(
0,
filePath.uri.lastIndexOf('/') + 1
)}QRCode.pdf`
await FileSystem.moveAsync({
from: filePath.uri,
to: pdfName,
})
console.log('PDF Generated', pdfName);
this.saveFile(pdfName);
} catch (error) {
console.error(error);
}
}
我正在创建生成二维码的 expo react 本机应用程序。当用户单击保存按钮时生成后,我想将二维码保存在 phone 中。我尝试了这段代码,但它给出了预期的 URL 方案 'http' 或 'https' 但 'data'
下面是我的代码
downloadFile(){
const uri = "data:image/pdf;base64"+base64_qr
let fileUri = FileSystem.documentDirectory + "QRCode.pdf";
FileSystem.downloadAsync(uri, fileUri)
.then(({ uri }) => {
this.saveFile(uri);
})
.catch(error => {
console.error(error);
})
}
saveFile = async (fileUri) => {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === "granted") {
const asset = await MediaLibrary.createAssetAsync(fileUri)
await MediaLibrary.createAlbumAsync("Download", asset, false)
}
}
有人可以帮助我吗?
async downloadFile(){
try {
let filePath = await Print.printToFileAsync({
html:' <div style = "margin-top: 40%; margin-left: 30%;"><h2 style = "margin-left: 50px; font-size: 45px;">LetMeIn</h2>'
+'<img src="' + base64_qr +'"'
+ 'alt="Red dot" style = "margin-left: 20px; margin-top: 10px;" />'
+ '<h2 style = "margin-top: 50px;">Scan the QR Code to check in</h2>'
+ '</div>',
width : 612,
height : 792,
});
const pdfName = `${filePath.uri.slice(
0,
filePath.uri.lastIndexOf('/') + 1
)}QRCode.pdf`
await FileSystem.moveAsync({
from: filePath.uri,
to: pdfName,
})
console.log('PDF Generated', pdfName);
this.saveFile(pdfName);
} catch (error) {
console.error(error);
}
}