Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating an entry with File fields #48

Open
fcmsilva opened this issue Apr 18, 2023 · 4 comments
Open

Updating an entry with File fields #48

fcmsilva opened this issue Apr 18, 2023 · 4 comments
Assignees

Comments

@fcmsilva
Copy link

Given a simple entry edit like this:

const exEntry = await stack
    .contentType("content_type")
    .entry("xxxxxxxx")
    .fetch();

exEntry.title = "newTitle";
exEntry.update();

Knowing that the entry that we're editing has a File field, this update will not work, with the following error:

{
  ...
  errorMessage: 'Entry update failed.',
  errorCode: 121,
  errors: {
    'hero.image': [ 'is not a valid upload.' ]
  }
}

I suppose this is because the update call is expecting just an array of uid's of each asset, but what fetch is retrieving is an object with the details of the asset. This might not be the expected behaviour, and make editing an entry with files harder, requiring some workarounds for the entry to be accepted when calling update.

I feel that adding an option in the fetch call to return only the assets' uid instead of the full object with details would be helpful. Either that, or for the update calls to support both uid strings and objects with an uid.

@uttamukkoji
Copy link
Contributor

Thanks @fcmsilva for raising the issue. If you want to update few fields you can directly use the update function on entry as follow:

const exEntry = await stack
    .contentType("content_type")
    .entry("xxxxxxxx");

exEntry.title = "newTitle";
exEntry.update();

Let us know if you still face issue with above example.

@fcmsilva
Copy link
Author

fcmsilva commented Apr 19, 2023

Thanks for your help, however fetch is required to get the values of each field. So when I'm editing an entry, I need the current values to make that change. For example, if I'm editing a entry with the following structure:

group: [
       {text: "Text", image: asset1}
       {text: "Text 2", image: asset2}
]

Now I want to change the text of the first element of the group, from "Text" to "Text 1".
In this case I'd need to edit a certain index of the group, but since the .entry method does not return the current entry's data, the only way I'd have of editing that data would be something like:

entry.group = [{text: "Text 1"}]
entry.update();

This obviously does not work, as it replaces the whole group with just group: [{text: "Text 1"}].

So from there the only option I see is using fetch to get the entry's data, editing the object, and calling update. But that would not work as mentioned in the issue, as the "image" fields would not be accepted.

For simple entries this is not a big issue, as just doing something like entry.image = entry.image.uid does the trick, but for more complex entries this requires traversing the whole entry tree to replace all occurrences, so I was wondering if it was something that could be simplified on the sdk's side

@cs-raj
Copy link
Contributor

cs-raj commented Sep 11, 2024

Hi @fcmsilva we will be looking into this and we will get back once we have update
cc: @harshithad0703 @sunil-lakshman

@vkalta
Copy link

vkalta commented Dec 16, 2024

Hi @fcmsilva , I tried to update an entry with file field and it seems to be working fine. Can you check again on your end? This might have been resolved.
cc: @cs-raj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants