Skip to content

Truncate long filenames#5116

Merged
ThiefMaster merged 1 commit intoindico:3.0.xfrom
UNOG-Indico:Truncate_filename
Oct 26, 2021
Merged

Truncate long filenames#5116
ThiefMaster merged 1 commit intoindico:3.0.xfrom
UNOG-Indico:Truncate_filename

Conversation

@vasantvohra
Copy link
Contributor

Users occasionally upload a file with a very lengthy name (>250) in the file field of the registration form; Mac and most OS allow up to 255 characters, but our servers return the error [Errno 36] File name too long.

Traceback:

File "/nas/indico.un/v2/indico-un/indico/indico/core/storage/models.py", line 208, in save
    self.storage_file_id, self.md5 = self.storage.save(path, self.content_type, self.filename, data)
  File "/nas/indico.un/v2/indico-un/indico/indico/core/storage/backend.py", line 252, in save
    with open(filepath, 'wb') as f:
StorageError: Could not save "event/1000135/registrations/5552/614104/102009-1633527965-AREMDCAM_AND_AUAG-CAMEROON-LETTER_OF_NOMINATIONS_ASSIGNMENT__RECOMMENDATION_FOR_ACCREDITATION_TO_THE7th_SESSION_OF_THE_MOP_TO_THE_AARHUS_CONVENTION_4TH_SESSION_OF_THE_MOPP_ON_PRTRs_THEIR_JHLS_AND_ASSOCIATED_MEETINGS_18-22_OCTOBER_IN_SWITZERLAN.pdf": 

[Errno 36] File name too long: u'/indico.un/v2/data/archive/event/1000135/registrations/5552/614104/102009-1633527965-AREMDCAM_AND_AUAG-CAMEROON-LETTER_OF_NOMINATIONS_ASSIGNMENT__RECOMMENDATION_FOR_ACCREDITATION_TO_THE7th_SESSION_OF_THE_MOP_TO_THE_AARHUS_CONVENTION_4TH_SESSION_OF_THE_MOPP_ON_PRTRs_THEIR_JHLS_AND_ASSOCIATED_MEETINGS_18-22_OCTOBER_IN_SWITZERLAN.pdf'

@vasantvohra
Copy link
Contributor Author

vasantvohra commented Oct 20, 2021

May I get a review here? I've tested this PR on v3

@ThiefMaster
Copy link
Member

Looks fine, but I'd like to have a unit test for this. I think we have a test for the function itself, so adding a new case covering this might be enough.

@vasantvohra
Copy link
Contributor Author

Hello, Morning, I added a test case to cover this. But, it is a hardcoded string of length 255, let me know if you'd prefer something autogenerated.

@vasantvohra vasantvohra force-pushed the Truncate_filename branch 3 times, most recently from 93cde8a to b201c08 Compare October 21, 2021 11:25
@ThiefMaster ThiefMaster enabled auto-merge (rebase) October 26, 2021 09:44
@ThiefMaster ThiefMaster added this to the v3.0 milestone Oct 26, 2021
@ThiefMaster ThiefMaster merged commit da84ade into indico:3.0.x Oct 26, 2021
@ThiefMaster ThiefMaster deleted the Truncate_filename branch October 26, 2021 09:49
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

Successfully merging this pull request may close these issues.

2 participants