Upload a file using REST API on sharedpoint and naming the file with the date

Nashef, Abdullah 1 Reputation point
2021-08-26T12:00:22.523+00:00

I'm trying to use the method POST to upload a file on SharePoint using REST API. However, I have to make a static name for the file.
Is there a possibility to name the file by the date of the moment the file is uploaded?
I'm using this link:

POST https://{site_url}/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/Add(url='{file_name}', overwrite=true)
Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft Partner Center API
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,126 Reputation points
    2021-08-27T02:14:08.963+00:00

    Hi @Anonymous ,

    If you are using the REST API in JS code to upload a file, you could name the file by the date of the moment like this:

    var now = new Date();  
    var fileName = now.toISOString().slice(0,10) +".docx";  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.