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

spo file add: A file or folder with the name already exists #6011

Open
MartinLoeper opened this issue May 1, 2024 · 13 comments · May be fixed by #6013
Open

spo file add: A file or folder with the name already exists #6011

MartinLoeper opened this issue May 1, 2024 · 13 comments · May be fixed by #6013

Comments

@MartinLoeper
Copy link

Priority

(Urgent) I can't use the CLI

Description

I want to replace a remote sharepoint file using the spo file add command, but the server complains that the file already exists.

Steps to reproduce

m365 spo file add \
        -u "xxxxxx" \
        --folder "xxxxxx" \
        --checkOut \
        --checkInComment 'mloeper locked file to modify entries' \
        --path "some local path"

Expected results

The file should be replaced. Since it is versioned, a new version should be added.

Actual results

{"error":"Eine Datei oder ein Ordner mit dem Namen \"xxxxx\" ist bereits vorhanden."}

aka "file already exists".

Diagnostics

No response

CLI for Microsoft 365 version

v7.6.0

nodejs version

20.11.1

Operating system (environment)

Linux

Shell

zsh

cli doctor

No response

Additional Info

No response

@MartinLoeper MartinLoeper changed the title spo file add: A file or folder with the name already exists spo file add: A file or folder with the name already exists May 1, 2024
@Adam-it
Copy link
Contributor

Adam-it commented May 1, 2024

Thanks for rising the issue. We will look into it ASAP

@milanholemans
Copy link
Contributor

Hi @MartinLoeper, how large is the file you are trying to add? Is it over 250MB?

@milanholemans
Copy link
Contributor

milanholemans commented May 1, 2024

Hi @MartinLoeper, could you give some more details about what you are trying to achieve with what kind of file? Seems like I can't reproduce this error.


While looking at the command, I found some other issues as well:

  • Verbose logs only work in debug mode
  • Undoing a check-out of a file always fails since there is no access token provided to the request.
  • Impossible to check in a file using a site relative URL, for example: --folder "/Shared Documents".

Already made a fix for these issues, if I can reproduce the issue, I'll update the PR with that fix as well.

@MartinLoeper
Copy link
Author

Hi @MartinLoeper, how large is the file you are trying to add? Is it over 250MB?

It's about 35 kB. So no, not nearly 250 MB

@MartinLoeper
Copy link
Author

Hi @MartinLoeper, could you give some more details about what you are trying to achieve with what kind of file? Seems like I can't reproduce this error.

While looking at the command, I found some other issues as well:

  • Verbose logs only work in debug mode
  • Undoing a check-out of a file always fails since there is no access token provided to the request.
  • Impossible to check a file using a site relative URL, for example: --folder "/Shared Documents".

Already made a fix for these issues, if I can reproduce the issue, I'll update the PR with that fix as well.

Do you think your changes already solve the issue? Should I give it a try by checking out your PR?

Thanks for looking into this so quickly!! 🚀

@MartinLoeper
Copy link
Author

Hi @MartinLoeper, could you give some more details about what you are trying to achieve with what kind of file?

We are basically sharing an encrypted file in sharepoint. So my usecase is to download the file, edit it and to upload it again.
Since the file is versioned, each upload creates a new version. The Sharepoint UI in the browser always asks what to do and we press "replace", which creates a new version.

I am currently automating this workflow using m365 cli and the following commands: spo file get and spo file add. I guess, I should add another one: spo file checkout before doing the get to be even more safe?

@milanholemans
Copy link
Contributor

Thank you for giving a bit more context.

This is how I tested the command (in PowerShell):

m365 spo file add -u $webUrl --folder "/Testlib" --checkOut --checkInComment "Lorem ipsum dolor sit amet" --path $filePath

And this is giving me this as a result (I executed it a few times):

image

I am currently automating this workflow using m365 cli and the following commands: spo file get and spo file add. I guess, I should add another one: spo file checkout before doing the get to be even more safe?

If you provide the --checkOut flag, we will check out your file before starting the upload, and check it back in again when it's finished. So technically you shouldn't need spo file checkout.

@milanholemans
Copy link
Contributor

milanholemans commented May 1, 2024

Do you think your changes already solve the issue? Should I give it a try by checking out your PR?

Please do! I'm a bit in doubt if this will fix your issue, but we can always try. Are you familiar with testing PRs locally, or should I provide some help?

@MartinLoeper
Copy link
Author

Do you think your changes already solve the issue? Should I give it a try by checking out your PR?

Please do! I'm a bit in doubt if this will fix your issue, but we can always try. Are you familiar with testing PRs locally, or should I provide some help?

I just checked out your branch and ran my command using --debug flag. This showed a lot of helpful stuff. In particular, the --folder parameter was pointing the remote file path instead of the file's basedir. Thus, the error message I got was misleading. It was masquerading a 404 error which was thrown earlier by checkout.

Thanks for leading me into the right direction @milanholemans!

@milanholemans
Copy link
Contributor

Aw, I see, so that means your issue is fixed now? If that's the case, I can have a look at it so we throw a clearer error instead of this misleading one.

@milanholemans
Copy link
Contributor

@MartinLoeper did you by any chance had the time to answer my previous comment?

@MartinLoeper
Copy link
Author

Not yet sorry, I am OOO this week and back next Monday.

@milanholemans
Copy link
Contributor

@MartinLoeper if you have some time in the coming days, please could you verify my previous comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants