We have not been able to get that working. It seems OneDrive want a binary stream for the file-content.
The manual we turned to is:
https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_uploadcontent
The method we wrote is:
- Code: Select all
function oneDriveUpload(parent_id,filename,file_content){
application.output(file_content)
var $url = "https://graph.microsoft.com/v1.0/";
var $client = plugins.http.createNewHttpClient();
var $access_token = RefreshToken(_to_app_user$current_user.office_365_refresh_token);
var post_url = '/me/drive/items/'+parent_id+':/'+filename+':/content';
var $post = $client.createPutRequest($url + encodeURI(post_url));
$post.addHeader("Authorization", "Bearer " +$access_token)
$post.addHeader("Content-Type", "text/plain");
// $post.addHeader("Content-Type", "application/json");
// $post.addHeader("Content-Type", "application/octet-stream");
$post.setBodyContent(file_content)
var executeRequest = $post.executeRequest();
return {
'getStatusCode': executeRequest.getStatusCode(),
'getResponseBody': JSON.parse(executeRequest.getResponseBody())
};
// /me/drive/items/{parent-id}:/{filename}:/content
}
With this method the file is being created, but empty.
We have tried several things to get the file_content variable as binary-data, but still did not manage to get the content in the OneDrive file.
With the file-plugin (JSFile.getBytes())we only can get byte-arrays, not binary data.
Is there a plugin available we don't know of that can create a binary stream we can use to pass the content to a OneDrive-file, or even a OneDrive/Office365 plugin that does all the work, or did anyone come up with another solution to write files to OneDrive ?