ACF video type media returns sourceUrl as false
ACF Image or File query response returns false for sourceUrl when the file is a video (tested with .webm and .mp4 formats).
Steps to reproduce:
- add a ACF Image or File field
- upload and save a video file (for example .mp4) to that field
- query the field and display sourceUrl
Mentions:
- guid returns the correct path to the file
- sourceUrl returns false
"testMedia": { "sourceUrl": "false", "title": "test", "guid": "http://test.test/wp-content/uploads/2019/06/test.mp4" },
I believe this is an issue with core WPGraphQL, not WPGraphQL for ACF.
We can leave this issue here for now, but it will likely get taken care of in the core plugin
I get the same error but with a pdf file. sourceUrl always return false.
Instead, I'm using the guid field.
Possibly related to this: a file is considered a MediaItem, so querying
... on File {
fileContent {
file {
mediaType
sourceUrl
mimeType
}
}
returns the sourceUrl as the filepath, but converts it to a .jpg, despite the file in this case being a .pdf:
{
"fileContent": {
"file": {
"mediaType": "file",
"sourceUrl": "http://danfoss-ixa.local/wp-content/uploads/2019/08/White-Paper-Introduction-to-MES-1001-pdf.jpg",
"mimeType": "application/pdf"
}
}
}
My theory is that it's actually getting the WordPress file thumbnail, which is obviously an image, but I don't know nearly enough PHP or WordPress to say for sure.
To replicate: create a custom post type File, and add the ACF File field to it. Upload a .pdf (or a .zip, or probably most other file types) and query it in GraphiQL. The file gets cast to a .jpg.
I've set up an ACF Block that accepts an mp4 video file upload. When I attempt to query the media item, the sourceUrl returns null. Does WPGraphQL allow for querying video files that are uploaded via ACF?
// query
query getVideo($videoId: ID!) {
mediaItem(id: $videoId, idType:DATABASE_ID) {
title
sourceUrl
}
}
// result
{
"data": {
"mediaItem": {
"title": "test-video",
"sourceUrl": null
}
},
"extensions": {
"debug": []
}
}
UPDATE: Looks like I can use mediaItemUrl or guid instead.
Closing as the core WPGraphQL schema exposes mediaItemUrl as indicated by @ttstauss and that field can be queried from fields in WPGraphQL for ACF that return a MediaItem