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

Messed downloaded filename #23

Open
bobonov opened this issue Nov 19, 2024 · 1 comment
Open

Messed downloaded filename #23

bobonov opened this issue Nov 19, 2024 · 1 comment

Comments

@bobonov
Copy link

bobonov commented Nov 19, 2024

python 3.12.7 in windows 11

Executing a task (tested with compress and unlock) and then downloading the file, result in messed name when saved on the disk.
the script is the following:


from pylovepdf.ilovepdf import ILovePdf

project_key = 'project_public_123mykey456'

pdf_file_path = "C:\\path\\to\\the\\file\\my_pdf.pdf"
download_dir = "C:\\download\\dir\\path\\"

ilovepdf = ILovePdf(project_key, verify_ssl=True)

task_compress = ilovepdf.new_task('compress')
task_compress.add_file(pdf_file_path)
task_compress.set_output_folder(download_dir)
task_compress.execute()
task_compress.download()
task_compress.delete_current_task()

task_unlock = ilovepdf.new_task('unlock')
task_unlock.add_file(pdf_file_path)
task_unlock.set_output_folder(download_dir)
task_unlock.execute()
task_unlock.download()
task_unlock.delete_current_task()

I would expect the file to preserve the name but as from the console I get the following


Uploading file...
File uploaded! Below file stats:
download_filename: C:\path\to\the\file\my_pdf_compress_19-11-2024.pdf 
filesize: 834572 
output_extensions: ["pdf"] 
output_filenumber: 1 
output_filesize: 198742 
status: TaskSuccess 
timer: 0.254 

Downloading processed file...
File downloaded!
Task delete status: 200 

Uploading file...
File uploaded! Below file stats:
download_filename: C:\path\to\the\file\my_pdf_unlock_19-11-2024.pdf 
filesize: 834572 
output_extensions: ["pdf"] 
output_filenumber: 1 
output_filesize: 828766 
status: TaskSuccess 
timer: 0.110 

Downloading processed file...
File downloaded!
Task delete status: 200 

The file is saved under the expected directory, but the filename is the whole original file path plus compress/unlock
C:\download\dir\path\path_to_the_file_my_pdf_compress_19-11-2024.pdf
C:\download\dir\path\path_to_the_file_my_pdf_unlock_19-11-2024.pdf

the path \path\to\the\file has been converted and included as part of the filename

@Mys7erio
Copy link

Mys7erio commented Dec 3, 2024

Hi, I went through the source code, and found that it is indeed the intended behaviour, since the library is calling the clean_filename() function which simply replaces / with _ just before writing the file.

I'd like to know @AndyCyberSec's opinion on this, and if he agrees, I can push a fix which saves the filename as is or some other naming convention which is desired.

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