1

Wherever I have the UI for uploading the document, I am easily able to use FormData api for uploading asynchronously to web api. Now I have a scenario where I need to upload a document based on file path without using UI or User Input so how can I do that?

Below is the code that I use when user uploads the file in form.

    var formData = new FormData();
    var myFile = $('#myFile')[0];
    formData.append("myFile", myFile.files[0]);
    $.ajax({
        url: url,
        type: 'POST',
        data: formData,
        contentType: false,
        processData: false,
        success: function (data, textStatus, xhr) {
            console.log(data);
        },
        error: function (xhr, ajaxOptions, rtnError) {
            alert(xhr.responseText + rtnError);
        }
    });
seUser
  • 1,093
  • 2
  • 10
  • 21
  • 1
    I don't think you can get access to a users machine w/o their permission. Their must be some kind of user interaction. – colecmc May 17 '16 at 18:09

1 Answers1

0

In general you cannot access to the client file system directly using JavaScript inside a browser (this is by design), and thus you will need the user to select the file manually to be able to upload it.

This question may further clarify what are the constraints in manipulating Files in JavaScript: Local file access with javascript

Community
  • 1
  • 1
Federico Dipuma
  • 17,655
  • 4
  • 39
  • 56
  • Thanks! I was just thinking if there is a way to manipulate that. For now, I ended up calling web api from server side! – seUser May 18 '16 at 14:46