Quantcast
Channel: Topic Tag: xml | WordPress.org
Viewing all articles
Browse latest Browse all 3201

Upload XML or CSV to Media library with WordPress API

$
0
0

Is it possible to upload XML to the media library using the WordPress API?

Background:
I can upload images with the WP API to the media library (with python) like this:

requests.post(endpoint, auth=auth, headers=headers, data=data)

where auth=(user, pw), headers = {
‘content-disposition’: f’attachment; filename=image.jpg’,
‘content-type’: ‘image/jpeg’,
}
and data is bytes of a jpg or png file.

I can also manually upload XML or CSV to the media library through the site dashboard.

But when I try to upload XML through the API where I change the headers to
headers = {
‘content-disposition’: f’attachment; filename=file.xml’,
‘content-type’: ‘application/xml’,
}
and data to the string (or bytes) of the XML document, I get this error:

‘code’: ‘rest_upload_sideload_error’, ‘message’: ‘Sorry, this file type is not permitted for security reasons.’, ‘data’: {‘status’: 500}

There is documentation here: https://developer.wordpress.org/rest-api/reference/media/#create-a-media-item

but I don’t see a field that lets you include the content much like a Post upload.

Any help is much appreciated!

Thanks!


Viewing all articles
Browse latest Browse all 3201

Trending Articles