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.

MediaLibrary.createAssetAsync - Created asset is completely different from original file

See original GitHub issue

šŸ› Bug Report

Environment

iOS (Not tested on Android)

Steps to Reproduce

  • Create a new asset from an existing file:
    • MediaLibrary.createAssetAsync(uri);
  • Get asset info of newly created asset:
    • MediaLibrary.getAssetInfoAsync(asset);
    • FileSystem.getInfoAsync(asset.uri, { md5: true });
  • Compare against original file info: FileSystem.getInfoAsync(uri, {md5: true });

Expected Behavior

Original file is copied over as an asset, unmodified or at least has a way to determine if a file has already been turned into an asset.

Actual Behavior

Newly created asset is completely different than original file. MD5 hash, filename, and size no longer match as the file has been opaquely transformed for some reason. There’s no way to compare if the original file actually exists as an asset because no asset properties match the original file properties.

It should also not create duplicate files. Currently you can pass the same uri into createAssetAsync and it will create a duplicate asset with a new filename.

Reproducible Demo

Check the console output: https://snack.expo.io/@justindmyers/bold-beef-jerky

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tsapetacommented, May 29, 2020

Could you try to use asset.localUri instead of asset.uri in FileSystem.getInfoAsync?

It should also not create duplicate files. Currently you can pass the same uri into createAssetAsync and it will create a duplicate asset with a new filename.

I don’t have good news – this is expected behavior. On iOS you can download an image from the internet, save it to photo library multiple times and you’ll get them duplicated. That’s how it works under the hood in the operating system and there is nothing we can do as far as I know.

0reactions
github-actions[bot]commented, Feb 18, 2022

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MediaLibrary - Expo Documentation
Saves the file at given localUri to the user's media library. Unlike createAssetAsync() , This method doesn't return created asset. On iOS 11+,...
Read more >
React Native/Expo Media Library exception when saving large ...
createAssetAsync () functions to hang and eventually throw a generic exception Unable to save file to external storage . With smaller files IĀ ......
Read more >
How to use the expo-media-library.MediaType function ... - Snyk
To help you get started, we've selected a few expo-media-library.MediaType examples, based on popular ways it is used in public projects.
Read more >
How to use Camera from Custom Code in a Draftbit app
Complete Code Snippet. Create a custom camera component from expo-camera. The expo-camera library provides a React component that allows snapping pictures usingĀ ...
Read more >
How to Save Files to a Device Folder using Expo and React ...
Save files to a device's internal storage so that it's publicly visible to other apps with one line of code.
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