A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
SharePoint Graph API Upload file
Benny Argo
0
Reputation points
I am able to upload files of the following type but I can only view one of the following file types after it is successfully uploaded.
- *.pdf - Works as expected. I am also able to replace the file.
- *.txt - File is uploaded but there is a lot of unwanted text added to the file. ----------------------------190622897699579092183602 Content-Disposition: form-data; name=""; filename="Test118.txt" Content-Type: text/plain Test Text File 118 ----------------------------190622897699579092183602--
- *.docx File is uploaded on the surface everything looks good. If I attempt to open the file from sharepoint I get the follow " Sorry. this file can't be opened for editing" and it will not open in Desktop App.
- *.xlxs - Same as the *.docx file.
I am using PHP to upload the files. Code snippet below.
$URL_String = "https://graph.microsoft.com/v1.0/sites/xxxx/drives/yyyyyy/root:/".$this->decode($folderID)."/".$filename.":/content";
$data = array('file' => new CURLFILE($filepath . "/" . $filename), 'filename' => $filename);
$ch = curl_init();
curl_setopt_array(
$ch, array(
CURLOPT_URL => $URL_String,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => array($_SESSION['access_token']),
)
);
$response = curl_exec($ch);
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
Microsoft Security | Microsoft Graph
An API that connects multiple Microsoft services, enabling data access and automation across platforms
Sign in to answer