cloud-py-api/nc_py_api

All special chars (like #) should be UrlEncoded

Closed this issue · 6 comments

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

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.

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.

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 :)

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.

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.