Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#40343 closed enhancement (wontfix)

REST API - set attachment upload directory on request

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

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 10 years ago.
Reads a time header to pass to wp_handle_sideload. Probably needs validation / errorhandling.
40343.diff​ (1.1 KB ) - added by curdin 10 years ago.
First proof-of-concept failed to work without time header.

Download all attachments as: .zip

Change History (4)

@curdin
10 years ago

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

#1 @curdin
10 years ago

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

@curdin
10 years ago

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

#2 @rmccue
10 years ago

  • Keywords dev-feedback 2nd-opinion removed
  • Milestone Awaiting Review
  • Resolution → wontfix
  • Status new → 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.