文件保存在/storage/emulated/0/Android/data/com..中,而不是下载文件夹react-native-image-to-pdf

wnavrhmk  于 2023-03-19  发布在  React
关注(0)|答案(1)|浏览(606)

PDF文件被保存在/storage/emulated/0/Android/data/com. and it is not access on the real device I want it to get moved to the download folder.在真实设备上无法访问我希望它被移动到下载文件夹

import RNImageToPdf from 'react-native-image-to-pdf';

....

    try {
      const options = {
        imagePaths:[],
        name: 'abc.pdf',
        maxSize: {
          // optional maximum image dimension - larger images will be resized
          width: 900,
          height: Math.round((height / width) * 900),
        },
        quality: 0.7, // optional compression paramter
      };
      const pdf = await RNImageToPdf.createPDFbyImages(options); // this is creating pdf and saving the file into storage/emulated/0/Android/data/com.
    } catch (e) {
      console.log(e);
    }
dohp0rv5

dohp0rv51#

如果您正在使用expo,您可以使用以下snippet

mport * as Permissions from 'expo-permissions';
import * as MediaLibrary from 'expo-media-library';

const perm = await Permissions.askAsync(Permissions.MEDIA_LIBRARY);
if (perm.status != 'granted') {
  return;
}

try {
  const asset = await MediaLibrary.createAssetAsync(downloadedFile.uri);
  const album = await MediaLibrary.getAlbumAsync('Download');
  if (album == null) {
    await MediaLibrary.createAlbumAsync('Download', asset, false);
  } else {
    await MediaLibrary.addAssetsToAlbumAsync([asset], album, false);
  }
} catch (e) {
  handleError(e);
}

相关问题