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.

[Android] File size of 0 with Camera!

See original GitHub issue

Hallo, i don’t anderstend. Your picker (^0.20.0) worked well on VW (Genomotion), but when i start app on Device (OnePlus One, CM13, Andriod 6.0.1) i can’t to upload pictures from Camera. I found only one difference: on vm: fileSize:6249 on device: fileSize:0 i think this is the problem or not?? my options: const options = { storageOptions: { skipBackup: true, path: 'images' }, allowsEditing: false };

response on device: fileName: "image-81d70921-110b-44f6-8f46-056e2adbd5b4.jpg", fileSize: 0, path: "/storage/emulated/0/Pictures/image-81d70921-110b-44f6-8f46-056e2adbd5b4.jpg", type: "image/jpeg", uri: "file:///storage/emulated/0/Pictures/image-81d70921-110b-44f6-8f46-056e2adbd5b4.jpg"

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:28 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
richsilvcommented, Dec 5, 2016

I’ve experienced the same issue with a OnePlus 3, and running some experiments with react-native-fs indicates that it takes around 8 seconds for the reported file size to go from 0 to the correct value, and trying to use the image in the interim (like posting it to a service via fetch) will fail.

Whilst the delay seems very long (post-processing?), it could be mitigated with an effective waitUntilSaved, but I can’t get this option to work for me, so I just have to add an arbitrary delay or keep checking every second or so.

@marcshilling I think this is the root of the problem, but I’m afraid I don’t have the Java skills to provide a PR which updates waitUntilSaved to delay the callback until the file has a size > 0. I hope this is helpful though.

1reaction
jemise111commented, Dec 6, 2016

@richsilv same problem I was seeing. The uri returned in the response does not actually contain anything for somewhere between 500ms and 10s.

I’m not sure how to fix but I did find a (very hacky) workaround that may work for some people. Sadly it’s all in JS:

something like…

class ImagePickerComponent extends React.Component {
  constructor(props) {
    super(props);
    this.imageCheckInterval = null;
    this.state = {imagePath: null};
  }

  componentWillUnmount() {
    if (!_.isUndefined(this.imageCheckInterval)) {
      clearInterval(this.imageCheckInterval);
    }
  }

  openImagePicker() {
    ImagePicker.showImagePicker(options, (response) => {
      
      const CHECK_IMAGE_URI_INTERVAL_MS = 1000;

      if (Platform.OS === 'ios') {
        this.setState({imagePath: response.uri});
      } else {
        this.imageCheckInterval = setInterval( () => {
          // Use getSize as a proxy for when the image exists
          Image.getSize(
            response.uri,
            () => {
              clearInterval(this.imageCheckInterval);
              this.setState({imagePath: response.uri});
            }
          );
        }, CHECK_IMAGE_URI_INTERVAL_MS);
      }
    });
  }

  render() {
    if (this.state.imagePath) {
      return <Image source={{uri: this.state.imagePath}} />
    } else {
      return <View style={styles.placeholder} />
    }
  }

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: capture image intent, photo file size is zero bytes?
Android : capture image intent, photo file size is zero bytes? ... I'm following this tutorial http://developer.android.com/training/camera/photobasics.html to ...
Read more >
CameraX | Android Developers
The RECORD size refers to the camera device's maximum supported recording resolution, as determined by CamcorderProfile. The MAXIMUM size refers to the ...
Read more >
Files Become 0 Bytes? Top 3 Ways to Restore Zero Byte Files
Hard disk is showing zero bytes? Files become 0 bytes. In this article, we will show you why a file becomes 0 bytes...
Read more >
Camera app that takes pics with a smaller file size? - Reddit
Which android camera app will simply give an option to take a much much smaller sized photo than the stock camera app that...
Read more >
Reduce Video File Size in Android mobile - YouTube
Videos recorded with Mobile Camera or a Screen Recorder app creates videos in large file size. It becomes very difficult to share videos ......
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