File re-upload issues

default discord avatar
appamics
2 months ago
1

If a file gets re-uploaded using the same file name the postfix changes to '-1' on the first re-upload and back to the original file on second re-upload. I would prefer if the file name would stay the same in this condition.



The second issue was with the rich-text field which was still refering to the old filename and URL. I thought the JSON data would only contain the collection name and the document ID but the full data of the media item is stored in MongoDB. This is dangerous and also wastes some space. In order to support any media file changes we have to query the media item anyway and storing an ObjectId would be sufficient. This would prevent other users running into the same issue.



Ideally the depth query parameter should be taken into account for rich-text data as well.

  • discord user avatar
    tylandavis
    Payload Team
    2 months ago

    Hey @appamics, regarding the first issue, the postfix is appended automatically only if that filename already exists. If you re-upload 'file.jpg' when 'file.jpg' already exists, it will be set to 'file-1.jpg'. If you re-upload a second time, 'file.jpg' is no longer taken, as the filename would be 'file-1.jpg'. You can always rename your files manually if you want to control the numbering.



    For the second issue, the data in the rich text field should have updated content if you've saved changes to the upload referenced. If that's not happening for your, there may be an issue with your set up. Besides that, if you want to just return the

    id

    or other specific fields, you can use an

    afterRead

    hook to modify the data returned.



    There's some discussion about adding

    depth

    to richText, or possible even a

    select

    property for granular control over what fields are returned in a relation. See this PR to see what's been discussed:

    https://github.com/payloadcms/payload/pull/1288
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.