To upload a file, use the /file-item/upload endpoint. The required parameters for this endpoint are:
- api-token - Your API token must be added to the request headers.
- itemIdContainer - The GUID of the item that will be the container of uploaded file.
JavaScript Code Example
The following JavaScript code example shows how use the REST API to upload a file using a HTML file input.
var formData = new FormData();
var fileInputElement = document.getElementById("fileInputElement");
// HTML file input
formData.append("fileFromHtmlInput", fileInputElement.files[0]);
var request = new XMLHttpRequest();
request.open("POST", "https://[YOUR_WORKSPACE_NAME].projectinsight.net/api/file-item/upload?itemIdContainer=[GUID]");
request.setRequestHeader("api-token", "[YOUR_API_TOKEN]");
request.onloadend = function ()
{
var result = JSON.parse(request.response);
//Handle the response here
};
request.send(formData);
C# Client Code Example
The following C# code example shows how use the REST API C# client to upload a file using the path to a local file.
using ProjectInsight.WebApi.Client;
ProjectInsightWebApiClient client = new ProjectInsightWebApiClient("https://[YOUR_WORKSPACE_NAME].projectinsight.net", "[YOUR_API_TOKEN]");
client.FileItem.Upload(itemIdContainer, pathToFile);
NOTE: Files that are uploaded to any item type other than a folder will be displayed under the "related items"
Comments
0 comments
Article is closed for comments.