Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createAssetAsync save the asset instead of just creating it. #1844

Closed
moshfeu opened this issue Jun 8, 2018 · 5 comments
Closed

createAssetAsync save the asset instead of just creating it. #1844

moshfeu opened this issue Jun 8, 2018 · 5 comments
Assignees

Comments

@moshfeu
Copy link
Contributor

moshfeu commented Jun 8, 2018

Environment

Environment:
OS: OS X El Capitan 10.11.6
Node: 8.10.0
Yarn: Not Found
npm: 5.8.0
Watchman: Not Found
Xcode: Not Found
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
expo: ^27.0.2 => 27.0.2
react: 16.3.1 => 16.3.1
react-native: https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz => 0.55.2

Diagnostics report:
https://exp-xde-diagnostics.s3.amazonaws.com/moshfeu-bda84927-2d35-4674-937b-ae59344ba3ed.tar.gz

Steps to Reproduce

  1. Use a Camera object to take image from the app
  2. Call the MediaLibrary.createAssetAsync with the image.urioutput from the prev step.

Expected Behavior

An Asset will be created but not stored in a default album such as DCIM.
Or I could delete this asset whenever I want. In this case the name of the default album (DCIM), will be stored in the Constants
Or there will be a method like removeAssetFromDefaultAlbum(asset) or something like this.

Actual Behavior

The asset saved in my default album (DCIM) instead of just been created.

I'm always keep saying "default album" but maybe it's default folder.

Some code

const photo = await this.camera.takePictureAsync();
const asset = await MediaLibrary.createAssetAsync(localUri);
// in this point, the asset will added to my DCIM album

Reproducible Demo

https://snack.expo.io/@moshfeu/createassetasync-repro

@tsapeta tsapeta self-assigned this Jun 9, 2018
@tsapeta
Copy link
Member

tsapeta commented Jun 9, 2018

Hey @moshfeu, thanks for creating that issue. An asset that you're creating needs to be saved somewhere, it cannot be just created. What I think we can do here is to add album parameter to createAssetAsync so you can place your newly created asset in the album that you want instead of DCIM. Is that something that you're going to achieve? I also like the idea to add a constant that will be pointing to DCIM album 👍

For now you can move your asset to the target album this way:
MediaLibrary.addAssetsToAlbumAsync(asset, album, false)
where the last argument means whether to copy the asset to the new album, in your case I assume you want to just move so it's false.

@moshfeu
Copy link
Contributor Author

moshfeu commented Jun 9, 2018

Thanks for the response @tsapeta .

add album parameter to createAssetAsync

Sounds great 👍

I can't use your solution because if the album is not exist, I need to create an album with this asset

album = await MediaLibrary.createAlbumAsync(ALBUM_NAME, asset);

so, when I try to move the asset to this album, I have 2. One from the album creation and the second from the moving.

For now, I have workaround:

const asset = await MediaLibrary.createAssetAsync(localUri);
const DCIM_id = asset.albumId as string;
await MediaLibrary.createAlbumAsync(ALBUM_NAME, asset);
await MediaLibrary.removeAssetsFromAlbumAsync([asset], DCIM_id);

@moshfeu
Copy link
Contributor Author

moshfeu commented Jul 12, 2018

@tsapeta what's the status? Just closed?

@tsapeta
Copy link
Member

tsapeta commented Jul 12, 2018

@moshfeu Oh yeah, I'm sorry I closed it by accident when I merged our internal PR that (I hope) fixes this issue. It should be available to the public in the very near future.

Unfortunately, it was not possible to add album parameter to createAssetAsync as I proposed previously, but we have added copyAsset parameter to createAlbumAsync - if you pass false there, then you will not have to remove the asset from the original album. It actually works just like copyAssets in addAssetsToAlbumAsync function. I believe it solves your problem or at least simplifies your solution.

@moshfeu
Copy link
Contributor Author

moshfeu commented Jul 12, 2018

Sounds good. Thanks!

@lock lock bot added the outdated label Jun 14, 2019
@lock lock bot unassigned Aasfga Jun 14, 2019
@lock lock bot locked and limited conversation to collaborators Jun 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants