Development discussions around Shopify APIs
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 |
---|---|
8 | |
7 | |
4 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By