Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:05:01+00:00 2026-05-27T10:05:01+00:00

I understand that the <input type=file> for the most part cannot be manipulated by

  • 0

I understand that the <input type="file"> for the most part cannot be manipulated by javascript for security reasons, but is it possible if I have a File object?

I have a drag area on a page, that I can get a File object out of. I don’t want to use the xhr.sendAsBinary, I’d rather just upload from a regular form with the target set as a frame.

I’ve tried doing something like

var select = document.getElementById('upload_1'); 
select.files[0] = myFile;
myForm.submit();

Is there a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:05:01+00:00Added an answer on May 27, 2026 at 10:05 am

    UPDATE

    It seems like you want to take the File object from the drop event and assign it to the <input> element. Unfortunately, you can’t do that. Only the user can select files; you can’t dynamically change the files which will be uploaded because browsers deny JavaScript this ability for security reasons.


    Since you said you have a drag area, I’m assuming you are using and targeting a browser that supports drag and drop. Note that not all browsers support drag and drop so my example here is limited to such browsers.

    With drag and drop, you can get the File object out of the drop event and you don’t need an input element.

    // when you attach the 'drop' event listener
    var dropzone = document.getElementById('drag_area'); // <-- ID of your drag area
    attachEvent(dropzone, 'drop', function(event) {
    
        var dt = event.dataTransfer;
        var fileList = dt.files;
        var file = fileList[0]; // you would have to change this if you allow multi-file upload
    
        uploadFile(file);
    
    });
    
    function uploadFile(fileToUpload) {
    
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "url", true);   // <-- provide the proper URL
    
        var form_data = new FormData();
        form_data.append('file', fileToUpload);
        xhr.send(form_data);
    
    }
    
    function attachEvent(element, type, fn) {
        if (element.addEventListener) {
            element.addEventListener(type, fn, false);
        } else if (element.attachEvent) {
            element.attachEvent('on' + type, fn);
        }
    }
    

    Note that this isn’t 100% browser compatible. Some browsers don’t support file uploading through XMLHttpRequest(). If you want to support those browsers, then you have to do something different.

    Finally, my example doesn’t consider using forms. If you want a form-based approach, please let me know. I can help you with that as well 🙂

    Let me know if you have any questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that you do something like: $('form').append('<input type=text name=color-1 value=Hello />'); But I
I understand that some countries have laws regarding website accessibility. In general, what are
I understand that they are both supposed to be small, but what are the
I understand that these methods are for pickling/unpickling and have no relation to the
I understand that requests are served by different threads, but do they all come
I would like to use HTML input file type in my aspx page to
I have a basic form consisting of input fields as well as a file
I understand that the title might not be descriptive enough, but I'm making a
hey, well I have this form <form method=POST action=''> <input type=hidden name=op value=download1> <input
I have a Google Instant style jQuery search script that queries a PHP file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.