我手爱特上传文件。在在线共享点的文件夹中的 web.xml 中,我只有 client_id、client_secret 和我的共享点的 url。不幸的是,我找不到解决方案。sharepointnodejsxmlfrench
我尝试使用 pnp 执行此操作,但该版本与 Nodejs 18 不兼容,并且我无法使用版本 3 和 4 执行此操作。我找不到其他允许我执行此操作的方法或库。我想将我的文件上传到我的共享点文件夹。目前没有什么有效的
以下是如何上传文件的基本示例:
const { ClientSecretCredential } = require('@azure/identity');
const { Client } = require('@microsoft/microsoft-graph-client');
const clientId = 'YOUR_CLIENT_ID';
const clientSecret = 'YOUR_CLIENT_SECRET';
const tenantId = 'YOUR_TENANT_ID';
const siteId = 'YOUR_SITE_ID'; // This is the ID of your SharePoint site
const targetFolderId = 'YOUR_TARGET_FOLDER_ID'; // This is the ID of the folder where you want to upload the file
const filePath = 'PATH_TO_YOUR_XML_FILE'; // Path to the XML file you want to upload
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const client = Client.initWithMiddleware({
authProvider: {
getAccessToken: async () => {
const token = await credential.getToken('https://graph.microsoft.com/.default');
return token.token;
},
},
});
async function uploadFile() {
try {
const fileContent = fs.readFileSync(filePath);
const fileName = path.basename(filePath);
const response = await client.api(`/sites/${siteId}/drive/items/${targetFolderId}:/${fileName}:/content`)
.put(fileContent);
console.log('File uploaded successfully:', response);
} catch (error) {
console.error('Error uploading file:', error);
}
}
uploadFile();