Uploading a media item with the wp-json API to a specific path

Don’t think this is possible, however will do a bit more research.

Since the functionality to expose this isn’t exposed by the server, you need to do something on the server side to enable this to happen. As you’re doing everything through a client-side script it wouldn’t be too hard to write a little plugin on the server side which you could call with your script:

  • Send it a media ID, and a destination path (i.e. the original URL)
  • It recevies that, changes the file location and then updates the media item path

You’d call it with e.g.:

curl POST "http://localhost/wp-json/wp/v2/movemymedia"

json: { mediaID: 1234, oldPath: "06/2018" }

or whatever.

Seems like a bit of work but would keep things neat in your existing structure.

Personally I prefer to do things like this on the server because the server knows all its local setup and could e.g. move files around easily. Maybe you want to consider flipping your script to work server side pulling the content instead of client side pushing it.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)