Upload image file using stagedUploadTargetGenerate

Hi all,

I am working the the Shopify admin API (API version: 2020-10) and i want to upload the product image using stagedUploadTargetGenerate. According to the documentation, i need to provide filename, mimeType and resource as input parameters and i used the following values:

const filename = '/u01/sony-vaio.jpg'; // Absolute path of the file to be uploaded
const mimeType = 'image/jpeg';
const resource = 'PRODUCT_IMAGE';

I made two requests and got the following response:

[
  {
    message: 'Internal error. Looks like something went wrong on our end.\n' +
      'Request ID: 3f5edabf-6b18-4ed8-a04b-5d17c5b47c3c (include this in support requests).',
    extensions: {
      code: 'INTERNAL_SERVER_ERROR',
      requestId: '3f5edabf-6b18-4ed8-a04b-5d17c5b47c3c'
    }
  }
]

[
  {
    message: 'Internal error. Looks like something went wrong on our end.\n' +
      'Request ID: 552f4e6d-bc19-4ebd-ac6f-6d395f292ad2 (include this in support requests).',
    extensions: {
      code: 'INTERNAL_SERVER_ERROR',
      requestId: '552f4e6d-bc19-4ebd-ac6f-6d395f292ad2'
    }
  }
]

I have contacted support and waiting for their repl. but in the mean time i want to check if there is anything i did wrongly. Here is part of my code for making the graphql request.

uploadImage: (auth, filename, mimeType, resource) => {
  const query = {
    query: `mutation stagedUploadTargetGenerate($input: StagedUploadTargetGenerateInput!) {
      stagedUploadTargetGenerate(input: $input) {
        userErrors {
          field
          message
        }
        url
        parameters {
          name
          value
        }
      }
    }`,
    variables : {
      input: {
        filename: filename,
        mimeType: mimeType,
        resource: resource
      }
    }
  };
  return shopifyGraphQLClient(query, auth);
}

Any ideas are welcome. Thanks.

Hey @ykyuen

I took a quick look at our logs and the exception we are seeing is “InvalidPathError”. You may want to try a relative path instead to see if that works. Also, take a look at this tutorial: https://shopify.dev/tutorials/manage-product-media-with-admin-api

1 Like

Hi Kevin,

Thanks for your reply. i finally get it working by using stagedUploadsCreate instead of stagedUploadTargetGenerate and previously i thought this request will upload the image so i try to specify the file path in the request parameters but it turns out the request only returns an AWS url for the real file upload by making another PUT request.

The article u posted https://shopify.dev/tutorials/manage-product-media-with-admin-api is very useful. Thanks again for your help.

Regards,
Kit

1 Like