I see I can retrieve a File object that has been uploaded, but how would one read the contents of the file from a custom app, can someone post a code snippet for achieving this?
Here's how I roughly achieved this:
import { GraphqlQueryError } from "@shopify/shopify-api";
import shopify from "./shopify.js";
import fetch from 'node-fetch';
const QUERY_FILES = ` {
files(first: 10) {
edges{
node{
__typename
createdAt
... on GenericFile {
id
url
}
}
}
}
}
`
export default async function someFunction(session)
{
const client = new shopify.api.clients.Graphql({ session });
try {
const filesqueryresponse = await client.query({
data: {
query: QUERY_FILES,
variables: {}
}
});
const fileurl=filesqueryresponse.body.data.files.edges[0].node.url;
console.log( 'sucecess: ', fileurl);
const response = await fetch( fileurl );
const filecontents = await response.text();
//filecontents now has content of file in string
...
}