Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3655

Upload file to SharePoint using REST API

$
0
0

I implemented SharePoint API connect/authorize/download functionality in an Excel workbook using VBA:

base_url = "SP URL/_api/web/"end_url = "GetFileByServerRelativeUrl('" & endpoint_urlurl = base_url & end_url & filepath & "')/$value"HttpRequest.Open "GET", urlHttpRequest.setRequestHeader "Authorization", "Bearer " & auth_tokenHttpRequest.Sendsresult = HttpRequest.responseTextsObject = HttpRequest.responseBodyfilepath = Replace(filepath, "%20", " ")filestring = Replace(filestring, "%20", " ")'MsgBox HttpRequest.StatusIf HttpRequest.Status = 200 Then'MsgBox HttpRequest.responseBody    Set MyStream = CreateObject("ADODB.Stream")    MyStream.Open    MyStream.Type = 1    MyStream.Write HttpRequest.responseBody    MyStream.SaveToFile filestring, 2    MyStream.CloseElseMsgBox HttpRequest.StatusMsgBox "Error - Connection to server failed"End If

I am struggling to adapt this for an upload use case.

From reading the SP API docs I see I need to adjust the url endpoint to /GetFolderByServerRelativeUrl('/Library Name/Folder Name')/Files/add(url='example.txt',overwrite=true)

How do I adapt the HttpRequest part? Is it as simple as changing the HttpRequest.Open "GET", url to HttpRequest.Open "SEND", url and then altering the below part?

Set MyStream = CreateObject("ADODB.Stream")    MyStream.Open    MyStream.Type = 1    MyStream.Write HttpRequest.responseBody    MyStream.SaveToFile filestring, 2    MyStream.Close

I tried to rewrite the MyStream part of the script but I am really unfamiliar with constructing this type of upload request.

I attempted to write a SEND version of the function but am unclear on the full scope of changes I need to make.


Viewing all articles
Browse latest Browse all 3655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>