

#File input to cambam code#
You need to meet the requirements listed in the section Running the code examples to use this example. The context for this example is a SharePoint-hosted add-in that uploads a file to a folder on the host web. The following code example uses the SharePoint REST API and jQuery AJAX requests to upload a file to the Documents library and to change properties of the list item that represents the file. Ĭode example 1: Upload a file across SharePoint domains by using the REST API and jQuery The following controls in your page markup. If you're developing a SharePoint Add-in, you can specify Write add-in permissions at the List scope.īrowser support for the FileReader API (HTML5).Ī reference to the jQuery library in your page markup.


Write permissions to the Documents library for the user running the code. To use the examples in this article, you'll need the following: For an example, see upload a file by using the cross-domain library. Provider-hosted add-ins written in JavaScript must use the SP.RequestExecutor cross-domain library to send requests to a SharePoint domain. The second example makes same-domain calls, like a SharePoint-hosted add-in would do when uploading files to the add-in web, or a solution that's running on the server would do when uploading files. The first example uses SP.AppContextSite to make calls across SharePoint domains, like a SharePoint-hosted add-in would do when uploading files to the host web. Get the list item that corresponds to the uploaded file by using the ListItemAllFields property of the uploaded file.Ĭhange the display name and title of the list item by using a MERGE request.īoth code examples in this article use the REST API and jQuery AJAX requests to upload a file to the Shared Documents folder and then change list item properties. These examples use the getfolderbyserverrelativeurl endpoint to reach the file collection, but you can also use a list endpoint (example: The array buffer is passed in the body of the POST request. The jQuery(document).ready function checks for FileReader API support in the browser.Īdd the file to the Shared Documents folder by using the Add method on the folder's file collection. This process uses the following high-level steps:Ĭonvert the local file to an array buffer by using the FileReader API, which requires HTML5 support. The code examples in this article use the REST interface and jQuery AJAX requests to add a local file to the Documents library, and then change properties of the list item that represents the uploaded file.
