Skip to main content
added 245 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

I suspect based on an answer at stackoverflowStackOverflow that something like this would work:

base64credentials="...... "
curl --request POST \
--url "http://www.yoursite.com/wp-json/wp/v2/media" \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

This should use tmp.png to create and upload a brand new attachment. You can then parse the result to retrieve the ID or success/failure and do other things with it, such as setting featured image meta etc.

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes

https://stackoverflow.com/questions/37432114/wp-rest-api-upload-image

First, your content-type should be image/jpegimage/jpeg and not application/jsonapplication/json, remember that content-type is supposed to reflect the data that you are passing and the POST media request expects an image.

Another change you have to make to accommodate the content-type is the way that you are passing the data. Instead of sending it with the source_url parameter, try passing it as a binary file.

One last thing I would mention is that the wp/v2 calls return 3XX status on a few occasions. It would be useful to follow those redirects and redo those requests to those new urlsURLs.

I suspect based on an answer at stackoverflow that something like this would work:

curl --request POST \
--url "http://www.yoursite.com/wp-json/wp/v2/media" \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes

https://stackoverflow.com/questions/37432114/wp-rest-api-upload-image

First, your content-type should be image/jpeg and not application/json, remember that content-type is supposed to reflect the data that you are passing and the POST media request expects an image.

Another change you have to make to accommodate the content-type is the way that you are passing the data. Instead of sending it with the source_url parameter, try passing it as a binary file.

One last thing I would mention is that the wp/v2 calls return 3XX status on a few occasions. It would be useful to follow those redirects and redo those requests to those new urls.

I suspect based on an answer at StackOverflow that something like this would work:

base64credentials="...... "
curl --request POST \
--url "http://www.yoursite.com/wp-json/wp/v2/media" \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

This should use tmp.png to create and upload a brand new attachment. You can then parse the result to retrieve the ID or success/failure and do other things with it, such as setting featured image meta etc.

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes

https://stackoverflow.com/questions/37432114/wp-rest-api-upload-image

First, your content-type should be image/jpeg and not application/json, remember that content-type is supposed to reflect the data that you are passing and the POST media request expects an image.

Another change you have to make to accommodate the content-type is the way that you are passing the data. Instead of sending it with the source_url parameter, try passing it as a binary file.

One last thing I would mention is that the wp/v2 calls return 3XX status on a few occasions. It would be useful to follow those redirects and redo those requests to those new URLs.

added 664 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

I suspect based on an answer at stackoverflow that something like this would work:

curl --request POST \
--url http"http://www.yoursite.com/wp-json/wp/v2/mediamedia" \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes

https://stackoverflow.com/questions/37432114/wp-rest-api-upload-image

First, your content-type should be image/jpeg and not application/json, remember that content-type is supposed to reflect the data that you are passing and the POST media request expects an image.

Another change you have to make to accommodate the content-type is the way that you are passing the data. Instead of sending it with the source_url parameter, try passing it as a binary file.

One last thing I would mention is that the wp/v2 calls return 3XX status on a few occasions. It would be useful to follow those redirects and redo those requests to those new urls.

I suspect based on an answer at stackoverflow that something like this would work:

curl --request POST \
--url http://www.yoursite.com/wp-json/wp/v2/media \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes

I suspect based on an answer at stackoverflow that something like this would work:

curl --request POST \
--url "http://www.yoursite.com/wp-json/wp/v2/media" \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes

https://stackoverflow.com/questions/37432114/wp-rest-api-upload-image

First, your content-type should be image/jpeg and not application/json, remember that content-type is supposed to reflect the data that you are passing and the POST media request expects an image.

Another change you have to make to accommodate the content-type is the way that you are passing the data. Instead of sending it with the source_url parameter, try passing it as a binary file.

One last thing I would mention is that the wp/v2 calls return 3XX status on a few occasions. It would be useful to follow those redirects and redo those requests to those new urls.

Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

I suspect based on an answer at stackoverflow that something like this would work:

curl --request POST \
--url http://www.yoursite.com/wp-json/wp/v2/media \
--header "cache-control: no-cache" \
--header "content-disposition: attachment; filename=tmp" \
--header "authorization: Basic $base64credentials" \
--header "content-type: image/png" \
--data-binary "@/home/web/tmp.png" \
--location

I did notice the capitalisation of Authorization needed adjusting, and you'll want to adjust the content type and data binary parameters to match your target file, let me know how that goes