duplicateResolutionMode: REPLACE Not Working in fileCreate Mutation Without File Ext

duplicateResolutionMode: “REPLACE” isn’t doing its job when I don’t include a file extension, and I end up with duplicate images in fileCreate mutation.
Also, if I try adding a .jpeg extension to the filename, I get a MISMATCHED_FILENAME_AND_ORIGINAL_SOURCE error. Oddly enough, everything works fine when both the originalSource and filename have matching extensions.

I run the mutation below with duplicateResolutionMode: “REPLACE”, it creates duplicate images if the filename doesn’t have an extension. The duplicates get a UUID tacked onto the filename (like 6734219301-040_F_). If I add .jpeg to the filename, I hit a MISMATCHED_FILENAME_AND_ORIGINAL_SOURCE error, so I can’t use it. But when I include matching extensions (e.g., .jpg) in both originalSource and filename, REPLACE works perfectly and overwrites the file.

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      id
      fileStatus
      alt
      createdAt
    }
    userErrors {
      code
      message
    }
  }
}
---
{
  "files": {
    "filename": "6734219301-040_F",
    "contentType": "IMAGE",
    "duplicateResolutionMode": "REPLACE",
    "originalSource": "https://{my_domain}/x7SOjVQrLQ_D1ZHDn0r0IOBcsW-xYC9DgZnCLCGBSrEpeAwrB62iDaYYKK8kVBKX7x-wMq4lRhi2tvq04sc1Z5nYDa5XOMK2mNLOOOtMauIy3SE=s1600"
  }
}

2 Likes

Hey @poccari ,

Happy to look in to this with you. Off hand, this does seem to be working as expected. When using duplicateResolutionMode: "REPLACE" , it only works when the filename is exactly the same as an existing file. Since you’re not including a file extension in your filename but the original filename likely has one, they’re being treated as different files.

Thanks @KyleG-Shopify

The original filename also doesn’t include an extension, but the files are still being duplicated.

Additionally, adding an extension to the filename causes an error, so I can’t include one.

How should I resolve this?

Hey Poccari, thanks for that context.

Just to confirm, when you query the filename, does it match exactly the input that you are providing in the update; and even then it’s creating a new file or error?

If you can share a little bit more about how your file is set up, that will help me better replicate this on my end as well.

Hi @KyleG-Shopify

Thanks for following up!

When I run the same query as the initial one, REPLACE doesn’t work, and a new file is created with a UUID appended to the filename.

Why does the behavior change depending on whether the filename includes an extension or not?

Hey! Thanks for following up.

I did some testing to replicate, and the issue here is that the filename field is always required to have an extension, and the extension has to match the original source. As long as those 2 are met, then the replacement should work. This explains why you’re seeing duplicate images when not including a file extension in your filename parameter, and why adding a .jpeg extension results in a MISMATCHED_FILENAME_AND_ORIGINAL_SOURCE error. The system is looking for an exact match including the extension for the REPLACE functionality to work properly.

When I tested with various combinations, I confirmed this behavior. Without the matching extension, the system either creates duplicates (using the default behaviour appending UUIDs to filenames) or returns errors.

Even when creating a new image with a filename that had no extension, I got an error confirming the extension is always required.

Hi @KyleG-Shopify

Thanks for the detailed explanation! I understand now that duplicates occur if the filename and originalSource don’t include matching extensions.

Is there any chance this behavior might be improved in the future?

I can pass on that feedback for sure. Just to confirm, would the improvement in your case be more options for the REPLACE function?

Hi @KyleG-Shopify

That’s probably it! We’re hoping for a solution where we can specify a filename without worrying about extensions, and Shopify would create a non-duplicated image.

Thanks! I’ve passed that feedback on to our product teams for you. Any changes to these behaviors will be noted in the developers changelog :tada:

1 Like