keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Cannot upload image in display mode "cards" in a relation when creating the related record

Open micreas opened this issue 3 years ago • 5 comments
trafficstars

  1. Create the following 2 schemas:
  ProductImage: list({
    fields: {
      image: image({
        storage: "local_images",
      }),
      product: relationship({
        ref: "Product.images",
        many: false,
      }),
    },
  }),
  Product: list({
    fields: {
      images: relationship({
        ref: "ProductImage.product",
        ui: {
          displayMode: "cards",
          cardFields: ["image"],
          inlineEdit: { fields: ["image"] },
          inlineCreate: { fields: ["image"] },
        },
        many: true,
      }),
    },
  }),
  1. Set up the storage for the images:
  storage: {
      local_images: {
        kind: "local",
        type: "image",
        generateUrl: (path) => `http://localhost:3000/images${path}`,
        serverRoute: {
          path: "/images",
        },
        storagePath: "public/images",
      },
    },
  1. Start the keystone app using yarn dev
  2. Go to admin UI and open the Product creation form
  3. Try to create the ProductImage inline.

It will just refresh the page and do nothing. However, it works in the edit mode once the Product record is created.

Node version: 16.16.0 Web browser: Chrome

micreas avatar Aug 13 '22 13:08 micreas

Update: Just found out that it happens for any inline entities in the Create view. Not just images.

micreas avatar Aug 14 '22 09:08 micreas

+1

https://github.com/keystonejs/keystone/issues/7808

au-top avatar Aug 17 '22 14:08 au-top

Hey @micreas do you get any error from the config setup related to the storage key? I tried to setup a config similar to yours but my typescript screaming for error that it won't recognize the key that I put in there (local_images). image

s-en-o avatar Aug 19 '22 09:08 s-en-o

Hey @s-en-o no, I don't. I just copied it from the documentation and it works. The only thing that I slightly tweaked was the generateUrl function. I hard-coded the localhost URL for this example.

micreas avatar Aug 19 '22 10:08 micreas

@micreas Found out that I need to provide all the properties for storage, mine was missing serverRoute.

image

s-en-o avatar Aug 20 '22 11:08 s-en-o

Resolved in #8177

borisno2 avatar Dec 20 '22 04:12 borisno2