Azure / Azure/wordpress-linux-appservice

_wp_attachment_metadata.sizes is empty for REST API uploads, but populated correctly when uploading via wp-admin

Open
#222 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
138
Forks
84
PR merge metrics
No merged PRs in 30d

Description

**Environment**
WordPress: 7.0.2
PHP: 8.3.29 (fpm-fcgi)
Server: Linux 6.6.139.1-1.azl3 x86_64
Web Server: nginx 1.28.0
Hosting: Azure App Service
Upload method under investigation: POST /wp/v2/media

**Description**
When uploading images through the REST API (POST /wp/v2/media), the image variants (thumbnail, medium, large, etc.) are successfully generated and written to both the local wp-content/uploads directory and Azure Blob Storage.
However, the attachment metadata returned by the REST API contains an empty sizes array:

```
"media_details": {
"sizes": {}
}
```

The key point is that uploading the exact same image through the standard wp-admin Media Library uploader works as expected:
Image variants are generated.
_wp_attachment_metadata['sizes'] is correctly populated.
The REST API subsequently returns the expected media_details.sizes.

This suggests the issue is specific to the REST API upload path rather than image generation itself, as the same server, PHP configuration, image editor, and storage backend all work correctly through the admin uploader.

**Steps to Reproduce**

1. Upload an image using POST /wp/v2/media.
2. Inspect the response.
3. Observe that media_details.sizes is an empty object ({}).
4. Verify that the variant image files exist in both:

- wp-content/uploads
- Azure Blob Storage

5. Upload the same image through the wp-admin Media Library.
6. Observe that media_details.sizes is correctly populated.

**Expected Behaviour**
media_details.sizes should contain the generated image variants regardless of whether the image was uploaded through the REST API or via wp-admin.

**Actual Behaviour**
When uploaded via the REST API:
✅ Image variants are physically generated.
✅ Variant files exist locally and in Azure Blob Storage.
❌ _wp_attachment_metadata['sizes'] is empty.
❌ media_details.sizes in the REST response is {}.

When uploaded through wp-admin:
✅ Image variants are generated.
✅ _wp_attachment_metadata['sizes'] is populated correctly.
✅ media_details.sizes is returned as expected.

**Question**

Does anyone have any ideas what could be causing this behaviour?

When uploading via the REST API (POST /wp/v2/media), the image variants are physically generated and stored correctly, but _wp_attachment_metadata['sizes'] is empty. As a result, the REST response also returns an empty media_details.sizes, and even the top-level width and height values in media_details are empty.

Uploading the exact same image via wp-admin correctly populates all of this metadata.

Is there a known reason why the metadata would not be populated when uploading through the REST API, even though the variant images are successfully generated?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing POST /wp/v2/media with the same image and compare its attachment metadata with the wp-admin upload path. Trace where the REST upload persists _wp_attachment_metadata after variants are generated, using the local and Azure Blob files as evidence. Done means media_details includes the generated sizes, width, and height for REST uploads.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, php, wordpress
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.