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

unable to upload file to sharepoint #4

Open
Shruthishetty93 opened this issue Nov 3, 2023 · 0 comments
Open

unable to upload file to sharepoint #4

Shruthishetty93 opened this issue Nov 3, 2023 · 0 comments

Comments

@Shruthishetty93
Copy link

Shruthishetty93 commented Nov 3, 2023

Hello Jakub, I need help for uploading files to my sharepoint site.
i did everything as you say in your docs, but when i try to upload i get this error.
Getting error as:

Client error: `POST https://xxxxx.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('https://xxxxxx.sharepoint.com/SitePages/Home.aspx?

my code
`$file = $request->file('file');
$newFileName = Helpers::reformatFileName($file->getClientOriginalName());
$allowedMimeTypes = ['image/png', 'image/jpg', 'image/jpeg', 'application/pdf', 'application/docx'];
if (!in_array($file->getMimeType(), $allowedMimeTypes)) {
return "File type not allowed.";
}
$filePath = 'submittal-files/' . $request->input('id');
$site_url = 'https://xxxxx.sharepoint.com';

	$library = 'Documents'; // Replace with your SharePoint library name
	$folder = 'xxxxx'; // Replace with your SharePoint folder name
	//sharepoint
	$app_id = 'xxxxxxx';
	$app_secret = 'xxxxxxx';
	$redirect_uri = 'https://url';
	$client = $this->sharepointClient->makeClient( $site_url, $app_id, $app_secret, $redirect_uri);
	$url = $client->getUserConsentUri();
	$auth_code = 'PAQABAAEAAAAtyolDObpQQ5VtlI4uGjEPSxAdxpjJBhHs_aK2NwCVnK5CHKtN_OzqVup0hPEQKp5k_3xo9gNhBXUBp7ErdsNvTwDF1erTf5iGtivKATZCkRciqXqOK71bEwdgB';
	$refreshToken = $client->getRefreshTokenFromAuthCode($auth_code);
	// Upload the file to SharePoint
	$upload_result = $client->uploadFile(
		$refreshToken,
		'https://mysite.sharepoint.com/Shared%20Documents/Forms/AllItems.aspx?viewpath=%2FShared%20Documents%2FForms%2FAllItems%2Easpx&id=%2FShared%20Documents%2FCQ%20De&viewid=75380876%2D96c8%2D4d78%2D86e6%2Ddb6f24b940f9',
		$filePath,
		\Storage::disk('local')->readStream($filePath));`
		
here i created app id & secret in both sharepoint and azure. 
Whether should i mention azure endpoint. 
if need where should i mention it. 
please help me out from this. 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant