seesharper
seesharper

Reputation: 3379

Upload "file" using Javascript

Here's the scenario:

I have this HTML page with a TextArea element on it.

When I click a upload button, I would like to upload the content of the textarea as a file.

I have found several examples that shows how to do this for an existing file on disc.

What I'm trying to do is edit text in the textarea and then upload the "file" to SkyDrive using the REST API provided by Microsoft.

Any idea how this could be done?

Upvotes: 2

Views: 2173

Answers (1)

maerics
maerics

Reputation: 156572

Just replace the upload button's action with a custom handler which performs an AJAX PUT request with content taken from the textarea. In jQuery it would be something like this (untested):

$('#my-submit-button').on('click', function(event) {
  $.ajax({
    type: 'PUT',
    url: 'my/skydrive/url',
    processData: false,
    data: $('#my-textarea').val(),
    success: function() { /* Success handler */ },
    error: function() { /* Error handler */ }
  });
  event.preventDefault();
});

Upvotes: 2

Related Questions