Creating asset from file URL creates weird filenames (not IMG_xxxx.yyy)

Originator:ole.begemann
Number:rdar://41019421 Date Originated:2018-06-11
Status:Open Resolved:
Product:iOS + SDK (Photos.framework) Product Version:11.4
Classification:Other Bug Reproducible:Always
 
Area:
Photos Framework

Summary:
When saving images or videos to the device's photo library using Photos.framework, the filenames of the saved files on disk (as seen by Image Capture.app and other importers) are not consistent. They depend on the API that was used to save the asset.

PHAssetCreationRequest.addResource(with:data:options:) produces consistent file names (IMG_xxxx.JPG), whereas addResource(with:fileURL:options:) produces "random" (unordered) filenames like "LQTI4681.JPG".

Steps to Reproduce:
Run the attached demo app *on a device* and follow the instructions:

• Run the app on a device. On my test devices, iCloud Photo Library was enabled. I don't know if this is significant.
• Connect the device to the Mac via USB.
• Open Image Capture on the Mac. Wait until Image Capture has loaded your device's Camera Roll.
• Tap the two buttons in the app to save a photo to the Photo Library. You'll be asked to grant permission. The first button uses PHAssetCreationRequest.addResource(with:data:options:) to save the asset. The second button uses addResource(with:fileURL:options:).
• Observe the filenames of the new items as they appear in Image Capture.

Expected Results:
PHAssetCreationRequest.addResource(with:data:options:) and addResource(with:fileURL:options:) behave the same: the asset filename on disk (as seen by Image Capture and other importers follows the IMG_xxxx pattern).

Actual Results:
When using addResource(with:fileURL:options:), Photos.framework saves the asset with a "random" filename like "HMTZ3319.JPG" or "LQTI4681.JPG".

Version/Build:
Tested on iOS 11.4 (iPhone 7) and iOS 12.0 beta 1 (iPad Pro 10.5). This has been an issue since at least September 2016 (possibly since the introduction of Photos.framework).

Notes:
- The attached demo.mov is a video of me using the sample app and explaining the issue.

- Note that we're not setting PHAssetResourceCreationRequest.originalFilename. It's about the filename of the asset on disk, not the originalFilename saved with the metadata.

- The issue also exists for videos, and is even more severe there because there doesn't seem to be a workaround. For photos, we can simply use the imageData variant, but videos are too large to load into memory.

- This issue may seem very unimportant because the filenames aren't visible anywhere on iOS, but many of our customers are advanced/pro photographers who care quite deeply about consistent (and ordered) filenames.

Comments

I replied:

Thanks for the reply. Yes, this is still an issue for us.

That said, if the original filename is not DCF compliant, it will get a DCF compliant name when transferred using Image Capture.

We are aware of this. Our issue is that the DCF-compliant file name that's being generated appears to be a "random" combination of letters and numbers, such as "HMTZ3319.JPG" or "LQTI4681.JPG". These filenames have no order and no apparent relation to the "usual" naming scheme "IMG_xxxx.JPG".

We'd like the file names in Image Capture to always follow the consistent scheme of "IMG_xxxx.JPG", regardless of which API is used for creating the asset. Many of our customers transfer photos using Image Capture and prefer a consistent file naming scheme.

Thanks for looking into this.

PS: In thinking about your reply, it occurred to me that I don't even know if the file name that appears in Image Capture is set by Photos.framework when the asset is created or if some other iOS component generates these file names "on the fly" when Image Capture or a similar app connects to the device. I can only report the behavior we're seeing when using the Photos APIs to save assets.

By ole.begemann at July 9, 2018, 3:52 p.m. (reply...)

Apple replied with this message:

This issue behaves as intended based on the following:

File names shown by Image Capture are limited by the PTP protocol. The file names must conform to the DCF (Design rule for Camera File system) protocol: https://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system

Also, you should be setting the original file name. We do try and use that when exporting assets out of Photos. That said, if the original filename is not DCF compliant, it will get a DCF compliant name when transferred using Image Capture. Note that using addResource(with:fileURL:options:) will set the original file name from the URL, if not provided.

Please update your bug report to let us know if this is still an issue for you.

By ole.begemann at July 9, 2018, 3:51 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!