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

deleteitem_internal on media resource, KeyError: 'media' #1484

Open
zaterio opened this issue Aug 15, 2022 · 1 comment
Open

deleteitem_internal on media resource, KeyError: 'media' #1484

zaterio opened this issue Aug 15, 2022 · 1 comment

Comments

@zaterio
Copy link

zaterio commented Aug 15, 2022

Environment

  • Python version: Python 3.9.2
  • Eve version: Eve==2.0

EXTENDED_MEDIA_INFO = ['content_type', 'name', 'length']
RETURN_MEDIA_AS_BASE64_STRING = False
RETURN_MEDIA_AS_URL = True
MEDIA_ENDPOINT = 'media'

I'm trying to delete files on the media endpoint, with deleteitem_internal, but apparently deleteitem_internal does not consider the media endpoint when is enabled, the same could be happening for other internal methods. It will also be valuable if when deleting an item from media (with deleteitem_internal), related items in the fs.files and fs.chunks collections are also deleted

Example:

fs.files:

_id: 62fa8c38f4c4954b8fef7e71
filename: "pic.jpg"
contentType: "image/jpg"
chunkSize: 261120
length: 48640
uploadDate: 2022-08-15T18:11:04.278+00:00

fs.chunks:
_id: 62fa8c38f4c4954b8fef7e72
files_id :62fa8c38f4c4954b8fef7e71
n: 0
data: BinData(0, '/9j/4AAQSkZJRgABAgAAAQABAAD//gAQTGF2YzU4LjkxLjEwMAD/2wBDAAgKCgsKCw0NDQ0NDRAPEBAQEBAQEBAQEBASEhIVFRUS…')

media_lookup = {'_id': 62fa8c38f4c4954b8fef7e71 }
deleteitem_internal('media', concurrency_check=False, suppress_callbacks=True, original=None, **media_lookup)

File "/home/trz/pushpull/lib/python3.9/site-packages/eve/methods/delete.py", line 99, in deleteitem_internal
resource_def = config.DOMAIN[resource]
KeyError: 'media'

same error is triggered when trying :
deleteitem_internal('fs.files', concurrency_check=False, suppress_callbacks=True, original=None, **media_lookup)

Regards

@ljluestc
Copy link

ljluestc commented Sep 1, 2024

from eve.methods.delete import deleteitem_internal
from pymongo import MongoClient

# Define media lookup
media_lookup = {'_id': '62fa8c38f4c4954b8fef7e71'}

# Delete the media item
deleteitem_internal('media', concurrency_check=False, suppress_callbacks=True, original=None, **media_lookup)

# Connect to MongoDB
client = MongoClient('mongodb://localhost:27017/')
db = client['your_database_name']

# Define file ID
file_id = '62fa8c38f4c4954b8fef7e71'

# Delete related files and chunks
db.fs.files.delete_one({'_id': file_id})
db.fs.chunks.delete_many({'files_id': file_id})

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

2 participants