Fixed broken attachment fetching with long filename

This commit is contained in:
Eliot Berriot 2020-01-02 14:23:05 +01:00
parent f0b72c8204
commit 7d528ba235
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
2 changed files with 25 additions and 3 deletions

View file

@ -80,9 +80,10 @@ def fetch_remote_attachment(attachment, filename=None, save=True):
for chunk in r.iter_content():
tf.write(chunk)
tf.seek(0)
attachment.file.save(
filename or attachment.url.split("/")[-1], File(tf), save=save
)
if not filename:
filename = attachment.url.split("/")[-1]
filename = filename[-50:]
attachment.file.save(filename, File(tf), save=save)
@celery.app.task(name="common.prune_unattached_attachments")