It throws an error getFolderByServerRelativeUrl Overwrite:false

Jyoti Rajpurohit 21 Reputation points
2022-09-23T10:38:36.28+00:00

Hi Team,

I want to upload multiple files in document library using spfx web part SharePoint so I am using getFolderByServerRelativeUrl and passing Overwrite:false but it throws an error and if I pass Overwrite:true it over writes the files.

how can i upload multiples files in document library example - book.txt, book(1).txt.

could you please help me in this?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,105 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,141 Reputation points
    2022-09-26T06:25:55.943+00:00

    Hi @Jyoti Rajpurohit ,

    To help you better, can you share your code and error message with me?

    In addition, according to my research and testing, if you want to upload files with the same name to the Document Library, you can try to select the option when you upload files with the same name: Keep both.

    244674-01.png

    My test result:
    244629-image.png

    Hope it can help you. Thanks for your understanding.

    -------------------------------------------------------------
    Update-------------------------------------------------------------

    I have reproduced your issue, When we use Overwrite:false ,we get 400 error.

    According to my research and testing, unfortunately, we cannot change the overwrite, and there are currently no APIs can avoid overwriting the files with the same name. As a workaround, if you want to upload files with the same name to the Document Library, please try the method above.

    The API is upload file to SharePoint : http://xxx.sharepoint.com/sites/xxx/_api/web/GetFolderByServerRelativeUrl('sites/Library Name/Folder Name')/Files/add(url='a.txt',overwrite=true)

    Thanks for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. Jyoti Rajpurohit 21 Reputation points
    2022-09-26T08:15:13.377+00:00

    Hi @Tong Zhang_MSFT , So here I am talking about code, using SPFX webpart.

    I want to upload multiple files in document library using spfx web part SharePoint so I am using getFolderByServerRelativeUrl and passing Overwrite:false but it throws an error and if I pass Overwrite:true it over writes the files

    244719-image.png
    244745-image.png