Solved

Access denied for stagedUploadsCreate field

EvilGranny
Shopify Partner
15 2 2

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 2

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

Replies 2 (2)

EvilGranny
Shopify Partner
15 2 2

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"

pixobe
Shopify Partner
5 0 0

To whoever facing this issue,

1. Ensure you have requested proper scopes

2. Check in partner dashboard if its reflected

3. Last and important step your app needs to be sales channel enabled (go to configuration).