maxim-kolesnikov / react-native-heic-converter

Convert your HEIC files with React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File Permissions Error

AndrewHenderson opened this issue · comments

I'm attempting to convert an HEIC file that I'm sharing to my app from iMessage. I only recently became aware of this file format and as far as I know, old iMessage images are the only source of HEIC files on one's iPhone. When I attempt to convert the file using this library, I receive the following permissions error.

iOS: 11.3.1
RN: 0.55.3

img

I was able to get this working by using React Native FS within my RN Share Extension to copy the HEIC file before attempting to convert it.

If I didn't copy it first, this library would error with a message stating it does not have access to write to the directory. Here is the original path of my file and the path after copying it.

file:///var/mobile/Library/SMS/Attachments/73/03/1BEC2DAA-60F7-48CF-84CC-B434F4246FD1/IMG_7048.HEIC

file:///var/mobile/Containers/Data/PluginKitPlugin/3CD048FC-778F-4343-8A34-F3F260147CF2/Documents/e5417bc3-b28c-4b0e-941c-b06c3688d7a4.HEIC

@AndrewHenderson
Thanks for your issue.
Sorry, that You had to wait for my answer too long.

Could your give me info from your development console in Chrome (just screenshot)?

RNHeicConverter
  .convert({ path: '/path/to/file.heic', })
  .then(({ success, path, error, base64 }) => {
    console.log({ success, path, error, base64 });
  });

~Maxim

@AndrewHenderson I'm getting a similar issue... the console output (wrapped it in a try catch) is pretty nondescript. { success: false, error: "Can't write to file" } using rn 0.56

@donnycrash thx for your report

@donnycrash closed by PR #4
Please reinstall your node_modules/ and try again with "react-native-heic-converter": "^1.2.0"
Let me know if your problem persists.

@maxim-kolesnikov Just seeing your replies, now.

I found the problem was not with this library itself, but iOS permissions writing to var/mobile/Library/SMS/Attachments/ which is a directory associated with SMS rather than the RN app.

Copying it to var/mobile/Containers/Data/PluginKitPlugin allows the converted .jpg to be generated in that directory.

const id = uuidV4();
let uri = this.state.filepath;
let extension = this.state.type.replace('image/', '');

if (extension === 'HEIC') {

  const destPath = `file://${RNFS.DocumentDirectoryPath}/${id}.${extension}`;

  await RNFS.copyFile(filepath, destPath); // create copy in directory safe for conversion

  // get converted file data
  const data = await RNHeicConverter.convert({
    path: destPath
  });

  uri = data.path; // set to path of newly created .jpg

  RNFS.unlink(destPath); // remove the copy of the .heic file
}

@maxim-kolesnikov works like a charm thank you

@maxim-kolesnikov Hello,
i have same error "success: false, error: "Can't write to file""
RN version - 0.59.9
react-native-heic-converter version - 1.2.0
Can you check it?

@o-dmytruk Hi!

"Can't write to file" is means that you are trying to write to a directory to which you do not have access or the directory does not exist.

What kind os path do you have?

@maxim-kolesnikov I use @react-native-community/cameraroll, then i check if image has heic extension i must convert it.
example path: 'ph://CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001/IMG_0111.HEIC'

@o-dmytruk
Thank you, it will be useful.
I will study this for a couple of days, and try fix

@maxim-kolesnikov Hi,
i try with alpha version,
but i have same error
success: false, error: "Can't write to file