WordPress.org

Make WordPress Core

#40343 closed enhancement (wontfix)

REST API - set attachment upload directory on request

Reported by: curdin Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: REST API Keywords: needs-unit-tests
Focuses: rest-api Cc:

Description

When using the Rest API to migrate content from a third-party system to WordPress it is useful to be able to specify the upload directory for systems that have month/day upload structures enabled. This can prevent a larger legacy system from dumping a large amount of files into the upload directory for the current month.

In my use case I would have ended up with 200'000+ files in the 2017/03 directory.

I propose adding another header to the /media endpoint that can be used to set the upload directory via a YYYY/MM date. This can then be passed to the wp_handle_sideload function.

I have attached a proof of concept, which likely needs validation

Attachments (2)

time_upload.diff (1.0 KB) - added by curdin 15 months ago.
Reads a time header to pass to wp_handle_sideload. Probably needs validation / errorhandling.
40343.diff (1.1 KB) - added by curdin 15 months ago.
First proof-of-concept failed to work without time header.

Download all attachments as: .zip

Change History (4)

@curdin
15 months ago

Reads a time header to pass to wp_handle_sideload. Probably needs validation / errorhandling.

#1 @curdin
15 months ago

  • Keywords dev-feedback 2nd-opinion needs-unit-tests added

@curdin
15 months ago

First proof-of-concept failed to work without time header.

#2 @rmccue
14 months ago

  • Keywords dev-feedback 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for filing this ticket! While I understand the desire for this, WordPress always stores images based on the file creation time. The only exception to this is when uploading images attached to an existing post, in which case it uses the date of that post instead. Apart from this, the creation date for a file cannot be set anywhere.

While there is a use-case for setting this manually, this is something that belongs in an import-specific API, and isn't something for the general-purpose API. This matches existing behaviour with things like GUIDs and modification times, which cannot be set manually.

Thanks for the ticket and patch anyway!

Note: See TracTickets for help on using tickets.