Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Trying to use the new files api to list the files uploaded in the shopify admin Files page (or through the files api).
That works fine but it looks like the file name or url cant be obtained from the api.
If the file is an image then the url can be obtained from the preview image but it doesnt work for other file types.
I was not familiar with graphql inline fragments, the way to get the file url is by using inline fragments on the returned concrete types.
files(first: 20, sortKey: CREATED_AT, reverse: true) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
alt
createdAt
fileStatus
... on GenericFile {
url
id
}
... on MediaImage {
id
image {
originalSrc
}
}
preview {
image {
height
transformedSrc(maxWidth: 300, maxHeight: 300)
width
}
}
}
}
}
This was really useful, thank you! But how would I go about looking up just ONE file by id?
Thanks!
fileCreate
mutation fileCreate($files: [FileCreateInput!]!) {
fileCreate(files: $files) {
userErrors {
field
message
}
files {
fileStatus
createdAt
fileStatus
... on GenericFile {
url
id
}
... on MediaImage {
id
image {
originalSrc
}
}
}
}
}
{
"files": {
"originalSource": "https://shopify.s3.amazonaws.com/tmp/55561781388/files/c7518ddddde-9e2081664da7/dddd.mp4",
"alt": "test",
"contentType": "FILE"
}
}
getFileUrl
query getFileUrl($id: ID!) {
node(id: $id) {
... on GenericFile {
id
url
}
... on MediaImage {
id
image {
originalSrc
}
}
}
}
{
"id": "gid://shopify/GenericFile/111111111111111"
}
User | RANK |
---|---|
4 | |
4 | |
4 | |
4 | |
3 |