Access denied for stagedUploadsCreate field

Solved
EvilGranny
Shopify Partner
15 2 1

Hey, I'm tring to create an app with remix, but I can't upload files. 

import { unstable_parseMultipartFormData, unstable_createMemoryUploadHandler } from "@remix-run/node";
import { uploadFile } from "~/models/file.server";
import { authenticate } from "~/shopify.server";

export const action = async ({request}) => {   
    const { admin } = await authenticate.admin(request);
    const uploadHandler = unstable_createMemoryUploadHandler({
        maxPartSize: 5_000_000,
    });
    const formData = await unstable_parseMultipartFormData(
        request,
        uploadHandler
    );
    const file = formData.get('file');

    const fileObject = {
        filename: file.name,
        fileSize: file.size.toString(),
        mimeType: file.type,
        resource: "FILE",
        httpMethod: "POST"
      }
    
      const result = await admin.graphql(`
        mutation stagedUploadsCreate($input: [StagedUploadInput!]!) {
          stagedUploadsCreate(input: $input) {
            stagedTargets {
              url
              resourceUrl
              parameters {
                name
                value
              }
            }
          }
        }
      `, {
        variables: {
          input: [fileObject],
      }});
}


There's an error:
GraphqlQueryError: Access denied for stagedUploadsCreate field.

I would be very grateful if someone could help me solve this problem.

Accepted Solution (1)
EvilGranny
Shopify Partner
15 2 1

This is an accepted solution.

To upload files, I needed to add permissions to scope in "shopify.app.toml" 

scopes = "write_products,read_files,write_files"

View solution in original post

Reply 1 (1)
EvilGranny
Shopify Partner
15 2 1

This is an accepted solution.

To upload files, I needed to add permissions to scope in "shopify.app.toml" 

scopes = "write_products,read_files,write_files"