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

All special chars (like #) should be UrlEncoded #191

Closed
tobenary opened this issue Dec 26, 2023 · 6 comments · Fixed by #192
Closed

All special chars (like #) should be UrlEncoded #191

tobenary opened this issue Dec 26, 2023 · 6 comments · Fixed by #192
Labels
bug Something isn't working fixed Fixed in last version

Comments

@tobenary
Copy link

tobenary commented Dec 26, 2023

Describe the bug

As per the example:
https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_client/files/upload.py
I'm trying to upload file to a specific location:
I tried the following methods:

# seven_z_upload_file = 'C:\\nextconnect\\00592295\\parsed\\12_26_2023_12_06PM_Logs (2)_parsed.7z'
# main_nc_folder = '/SFDC_CASES/SFDC#'
# ticket_id = '1234'
# os.path.split(seven_z_upload_file)[1] = '12_26_2023_12_06PM_Logs (2)_parsed.7z'
with open(seven_z_upload_file) as f:
    file_path = main_nc_folder + ticket_id + '/' + os.path.split(seven_z_upload_file)[1]               
    nextcloud_file_object = nc.files.upload_stream(file_path, f)`

I also tried removing the first '/' with main_nc_folder.removeprefix('/') - nothing
I tried using the FSNode:

nc.files.upload_stream(nc.files.mkdir(main_nc_folder + '#####' + ticket_id).full_path + os.path.split(seven_z_upload_file)[1], seven_z_upload_file)

# nc.files.mkdir(main_nc_folder + '######' + ticket_id).full_path + os.path.split(seven_z_upload_file)[1] == 
'files/tomerb/SFDC_CASES/SFDC######00592295/12_26_2023_12_06PM_Logs (2)_parsed.7z'


path_temp = nc.files.mkdir(main_nc_folder + '###' + ticket_id).full_path`

file_path = main_nc_folder + ticket_id + '/' + os.path.split(seven_z_upload_file)[1]               
    nextcloud_file_object = nc.files.upload_stream(file_path, f)`

If it is working, I'm getting filename on my /SFDC_CASES named: SFDC

I'm getting 404, 409

@bigcat88 , Please LMK what should I do.
I can also contribute to writing more docs if needed.

Steps/Code to Reproduce

# seven_z_upload_file = 'C:\\nextconnect\\00592295\\parsed\\12_26_2023_12_06PM_Logs (2)_parsed.7z'
# main_nc_folder = '/SFDC_CASES/SFDC#'
# ticket_id = '1234'
# os.path.split(seven_z_upload_file)[1] = '12_26_2023_12_06PM_Logs (2)_parsed.7z'
with open(seven_z_upload_file) as f:
    file_path = main_nc_folder + ticket_id + '/' + os.path.split(seven_z_upload_file)[1]               
    nextcloud_file_object = nc.files.upload_stream(file_path, f)`
nc.files.upload_stream(nc.files.mkdir(main_nc_folder + '#####' + ticket_id).full_path + os.path.split(seven_z_upload_file)[1], seven_z_upload_file)

# nc.files.mkdir(main_nc_folder + '######' + ticket_id).full_path + os.path.split(seven_z_upload_file)[1] == 
'files/tomerb/SFDC_CASES/SFDC######00592295/12_26_2023_12_06PM_Logs (2)_parsed.7z'


path_temp = nc.files.mkdir(main_nc_folder + '###' + ticket_id).full_path`

file_path = main_nc_folder + ticket_id + '/' + os.path.split(seven_z_upload_file)[1]               
    nextcloud_file_object = nc.files.upload_stream(file_path, f)`

Expected Results

File named: '12_26_2023_12_06PM_Logs (2)_parsed.7z', located at folder: /SFDC_CASES/SFDC######00592295/

Actual Results

(When it's working) I'm getting a file named SFDC (no extension at all)

Setup configuration

nc_py = 0.71

@bigcat88
Copy link
Member

dir_path = "/SFDCCASES/SFDC######00592295/"
nc.files.makedirs(dir_path)

Do not work, for some reason "#####" is missing and it creates "/SFDCCASES/SFDC" folder.
Looks like a bug from the first view, will take a closer look a bit later.

@bigcat88 bigcat88 added the bug Something isn't working label Dec 26, 2023
@tobenary
Copy link
Author

image

image

@bigcat88
Copy link
Member

dir_path = "/SFDCCASES/SFDC######00592295/"
nc.files.makedirs(dir_path)

Do not work, for some reason "#####" is missing and it creates "/SFDCCASES/SFDC" folder. Looks like a bug from the first view, will take a closer look a bit later.

I will fix this tomorrow and publish a new version.

Looks like all ### should be UrlEncoded, my bad, missed that.

@tobenary
Copy link
Author

You're right!
I changed the hash sign to underline, it worked: (with and w/o the '/' at the beginning of the path)
nc.files.upload_stream('SFDC_CASES/SFDC_00592295/12_26_2023_12_06PM_Logs (2)_parsed.7z', seven_z_upload_file)
image

2 hours gone... but at least I found the bug :)

@bigcat88
Copy link
Member

2 hours gone... but at least I found the bug :)

Next time, if something doesn't work properly on the first or second try, feel free to create a discussion or issue, as my goal is to make using Nextcloud in Python intuitive.

@tobenary
Copy link
Author

Everything is ok!
You spent your time building it, and I got into this package from the Nextcloud forum, I previously used the Owncloud, but for some reason, it stopped working with my needs.

As I said, I'm a new Pythonist, and I am willing to help with some examples.

@tobenary tobenary changed the title Uploading file to another folder but root All special chars (like #) should be UrlEncoded Dec 26, 2023
@bigcat88 bigcat88 added the fixed in upcoming release fix will arrive with next release label Dec 26, 2023
bigcat88 added a commit that referenced this issue Dec 26, 2023
Fixes #191 .

Looks like this error was introduced in `0.7.0` version, where I
refactored all code.

_Fixed and adjusted tests suite to detect this_

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
@bigcat88 bigcat88 added fixed Fixed in last version and removed fixed in upcoming release fix will arrive with next release labels Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Fixed in last version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants