question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can not readFile that captured as tmpfile

See original GitHub issue

readFile() method of both “react-native-fs” and “rn-fetch-blob” works well for static asset files or the output of “react-native-camera” library. But the readFile() method can not read the file that captured via “react-native-view-shot” as tmpfile.

react-native@0.52.2 react-native-view-shot@2.3.0 react-native-fetch-blob@0.10.8 rn-fetch-blob@0.10.11 react-native-fs@2.10.14

class SomeComponent extends Component {
  async captureAndReadFile() {
    try {
      let filePath = await this.viewShot.capture() ;
      let data = await RNFS.readFile(filePath, 'base64');  // or RNFetchBlob.fs.readFile(filePath, 'base64');
      return data && new Buffer.from(data, 'base64'); 
    }
    catch(err) {
      console.warn(err);
    }
  }

  render() {
    return(
      <View>
        <ViewShot 
          ref={ref => this.viewShot = ref}
          options={{ format: 'jpg', quality: 0.8 }}
        />
        <Button title="Press" onPress={this.captureAndReadFile.bind(this)}
      </View>
    );
  }

Am I missing something ? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
serhiipalashcommented, Nov 13, 2018

Hi @gre ! I think this bug is still active.

Expo.takeSnapthosAsync has this bug in Expo 31 compare to Expo 30 (iOS tested). In Expo 31 takeSnapthosAsync was updated to use react-native-view-shot v2.5.0, and now takeSnapthosAsync result “tmpfile” uri is not compossible with Expo.MediaLibrary or Expo.FileSystem any more. That is because “tmpfile” uri path is in /private/var/... and Expo.MediaLibrary and Expo.FileSystem can only work with paths that are in public system scope /var/.... When you try to save taken view snapshot to user photos or temporary dir, you will see an error “Couldn’t read …”.

As I remember in Expo 30 version of react-native-view-shot was something around v1.1.0.

0reactions
grecommented, Aug 11, 2019

I think this is fixed. I was properly able to get the data from file and render it back in https://github.com/gre/react-native-view-shot/commit/8a6ea61c300d4ee7cb4fae2b9eec28d3c0b95dfe

works on iOS and Android.

Please report back if you are still having an issue (writing an example to reproduce the bug is the best)

Read more comments on GitHub >

github_iconTop Results From Across the Web

eclipse: Project not built due to "Could not read file
With the existence of this temp file, eclipse failed to build my project. The problem window said: The project was not build due...
Read more >
why php can not see /tmp files - Unix & Linux Stack Exchange
I am running Ubuntu 18.04 and /usr/lib/systemd did not contain any services for http or apache2. However, I executed the following command:
Read more >
Execute failed: Cannot read file ...
Encountered this very scary error with a long-running workflow during the night occurring at the “Table Row To Variable Loop Start” node.
Read more >
How to use Temporary Files in C# - Dave on C-Sharp
Create a new Console Application and add a method called CreateTmpFile . In this method we will use the System.IO.Path class to create...
Read more >
Fix errors that relate to reading or creating files in the temp or ...
To correct this problem you may need to change your environment variable for $TMP or $TEMP, to somewhere you have write access. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found