Passing path to uploaded file from HTML5 drag & drop to input field

前端 未结 3 1063
死守一世寂寞
死守一世寂寞 2020-12-29 09:36

I\'m working on an application (in Node.js, which is irrelevant for this case) which allows the user to upload an image. It works fine using a form with an input (type=\"fil

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 10:15

    I find that the hidden field set in reader.onload (see answer by @challet) is not set when acccessed in code behind. I am using asp.net and a WebForms project. To access the hidden fields I have to prepend MainContent_ to the field names. aspx code is below

    
    
    ...
    
    
    ...
    
        

    Drag image to this Drop Zone ...

    ...

    I access the hidden fields from c# as shown below

    protected void btnDrop_Click(object sender, EventArgs e)
             {
                 string FileName = DroppedFileName.Value;
                 string FileContent = DroppedFileContent.Value;
             }
    

    If I use Internet Explorer as the target browser (not running VS as Admin as this disables drag/drop!) and set a breakpoint in the reader.onload() function the hidden field DroppedFileContent contains the encoded file content, but when I try to access it from btnDrop_Click it only contains "Test" as set before reader.onload() and does not contain the encoded file content. The field DroppedFileNam.Value is as set in the Javascript.

提交回复
热议问题