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

Adding an image to a card overwrites the file name #6622

Closed
Anthropos888 opened this issue Jul 5, 2020 · 15 comments
Closed

Adding an image to a card overwrites the file name #6622

Anthropos888 opened this issue Jul 5, 2020 · 15 comments

Comments

@Anthropos888
Copy link
Contributor

Reproduction Steps
  1. Review a card with an image > Menu > Edit note
  2. Tap on the paper clip next to the image field
  3. Tap on "Gallery" button, select an image "test.jpg" from your gallery and save the changes
Expected Result

The image "test.jpg" will be copied to the collection folder

Actual Result

Instead, the image will be renamed to some horrible construct like img_202007050926164513682973119384157.jpg

Some of my decks rely on the image file name that I choose myself, so by renaming them automatically the deck doesn't work anymore :-(

Also I didn't realize this automatic change before because there's no such message. Therefore I would recommend to show a message that the image was renamed OR show the file name below the (recently added display of the) image size (which would be a useful information anyway).

Debug info

AnkiDroid Version = 2.12.0beta3

Android Version = 9

ACRA UUID = 1f29f610-893a-403f-83d5-25a26ba97fe0

Research

Enter an [x] character to confirm the points below:

  • [ x] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid
  • [ x] I have checked the manual and the FAQ and could not find a solution to my issue
  • [ x] I have searched for similar existing issues here and on the user forum
  • [x ] (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
@david-allison
Copy link
Member

Result of #6543. @mikehardy

@mikehardy
Copy link
Member

Yeah, there is an opposite case where if we don't rename the image there can be collisions.

The "horrible" construct is otherwise known as a "unique name" ;-)

So I want to say that as Anki ingests media there can be no guarantee of filenames that result, I think that is a correct statement, and I think stating otherwise is technically wrong. The following is based on that.

From a user experience perspective, what would work for you?

User messaging with the ability to copy to clipboard the message we will use internally?
A "speculative" (we can try it, might work, might not) image rename?

I'm not sure the best way to handle it, all I know for sure is that if we don't create guaranteed unique names there are other problems.

@Anthropos888
Copy link
Contributor Author

Haha, sorry for the "horrible", it's just my user experience and a file name that exceeds my phone's screen is really unpleasant.

Question: why do we need to rename the images? Anki desktop saves them as they are. And beforehand it checks for name conflicts and renames the image to "test (1).jpg" if "test.jpg" already exists.

@mikehardy
Copy link
Member

Ah, I should explicitly recognize that any choice that proposes a limited number of options is the "fallacy of false choice"

So Desktop is handling the collision, but they're generating unique names that users like. Our current "unique name" algorithm is provably unique but sucks for users (I'll grant that!)

So a proposed solution would be:

  • attempt to copy the image in by it's original name, use that if unique
  • only if not unique rename to "original name (N).extension" where 'N' is the number required to be unique, incrementing past whatever number was there previously? I suppose we would need to message that to the user somehow, perhaps a quick 'we did this" with only "OK" dialog is sufficient?

...and to again recognize the false choice, anything is possible (within reason) if you have a cleaner idea?

@Anthropos888
Copy link
Contributor Author

Anthropos888 commented Jul 5, 2020

attempt to copy the image in by it's original name, use that if unique

Perfect!

only if not unique rename to "original name (N).extension" where 'N' is the number required to be unique, incrementing past whatever number was there previously?

Perfect!

I suppose we would need to message that to the user somehow, perhaps a quick 'we did this" with only "OK" dialog is sufficient?

Anki desktop doesn't do this. But yes, a message that "xyz.jpg" already exists and thus was renamed to "xyz (n).jpg" would be a hell of a clean approach.

@mikehardy
Copy link
Member

Great, I'll see what I can do - it shouldn't be too much of a change vs the current state after the crop PR landed
As ever, I appreciate that you test the betas and take the time to work with us on improvements. It makes a real difference, thanks @Anthropos888

@mikehardy mikehardy self-assigned this Jul 5, 2020
@david-allison
Copy link
Member

Another Proposal:

  • Copy to the cache with the unique name
  • Store original name
  • When saving to the collection, if no conflict occurs, then save using the original name
  • Otherwise, warn and provide the user with the options:
    • Replace
    • Rename - Text box with reasonable default name
    • Cancel

@mikehardy
Copy link
Member

Yeah - the implementation could follow that path - the cache step (before moving to collection) is independent

@Anthropos888
Copy link
Contributor Author

Or if it is easier to implement, then here's another idea:

  • leave everything as it is
  • but show the file name below or above the file size (which would be useful anyway)
  • add a button "Rename" that allows users to input their own file name (give a warning if file name already exists)

This would also solve one of my other issues: #5192 :-D

@mikehardy
Copy link
Member

That could also work. I'll consider both when I set up tools in the area and start work

@dae
Copy link
Contributor

dae commented Jul 6, 2020

FWIW, recent Anki versions will append a hash of the content to the filename on a conflict. Some workflows always used the same filename (eg "image.jpg"), and as the numbers increment and are predictable, (1), (2) and so on could lead to conflicts with different files added on another device prior to syncing.

@mikehardy
Copy link
Member

Very interesting @dae ! thanks for that tidbit. @Anthropos888 this is unfortunately a strike against the idea of keeping the "make name unique" method producing really nice names if we have direct experience it has failure modes. I'll have to think on this but based on the new experience shared by Damien I'm thinking that any proposed fix would still have a nasty-looking name as a main component (possibly with editing power, but defaulting to a big ugly name).

@github-actions
Copy link
Contributor

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Oct 25, 2020
@github-actions github-actions bot closed this as completed Nov 1, 2020
@david-allison david-allison reopened this Nov 1, 2020
@mikehardy mikehardy removed this from the 2.14 release milestone Nov 10, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2021

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

@github-actions
Copy link
Contributor

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants