Create file on SkyDrive

Go To


I'm trying to create a new file on SkyDrive using JavaScript.

The closest thing I have so far is to create a file, but without any content.

function upload() {
                path: "me/skydrive/files/testfile8.txt",
                method: "PUT",
                body: "Some file content"
            }, function (response) {onError(response) });

                function onError(response) {



Does anybody know how to create a new file on SkyDrive and pass a string as the file contents.

I have also tried using Ajax

                type : "PUT",
                url: "" + ACCESS_TOKEN,
                data: "SOMEDATA",                    
                processData: false,                                        
                success: function() { alert('Success!' );},
                error: function(a,b,c) { alert('Error!' + a + b + c); }

This just returns a internal server error and leaves me pretty helpless :)


2012-04-03 22:30
by seesharper
When you are authenticating the user to get the access toke, what are scopes you have used - Prashant 2013-04-29 08:19


Sorry to reply to an old thread.

How about the following code?

It creates a file called 'hello.txt' that contains the string 'Hello, world!' in your SkyDrive folder.

var CLIENT_ID = '!!!!!!!!CLIENT ID!!!!!!!!';
var REDIRECT_URI = '!!!!!!!REDIRECT URI!!!!!!!';
var filename = 'hello.txt';
var content = 'Hello, world!';
var access_token = '';
    client_id: CLIENT_ID,
    redirect_uri: REDIRECT_URI
}).then(function (response) {
    return WL.login({scope: ['wl.signin', 'wl.skydrive', 'wl.skydrive_update']});
}).then(function (response) {
    access_token = response.session.access_token;
    return WL.api({path: 'me/skydrive'});
}).then(function (response) {
    var url = response.upload_location + filename + '?access_token=' + access_token;
    var xhr = new XMLHttpRequest();'PUT', url);
    xhr.onload = function () {
        alert('success:', xhr.responseText);
    xhr.onerror = function (error) {
        alert('XHR error:', xhr.responseText);
    xhr.send(new Blob([content]));
}, function (error) {
    alert('error:', error);

BTW, This thread may also help you.

2013-11-17 08:31
by seikichi