Is a reliable javascript file upload only

I need a reliable way to upload a file. This means that I want to be able to handle interrupts, errors and pauses.

So my question is: Maybe something like the following, using javascript only on the client .

If so, I would like pointers to appear in libraries, textbooks, books, or implementations. If not, I would like to explain why this is not possible.

Scenario:

  • Open large file
  • Divide it into parts

For every piece I would like

  • Create checksum and add to data
  • Publish data to the server (the server will check if the data is loaded correctly)
  • Check the web page on the server to see if it is loaded normally.
  • If yes, download the next part, if not try again

Suppose that all messages on the server are accompanied by the corresponding metadata (sessionid and whatnot).

+3
source share
4 answers

No. . You can use a certain number of hackers to start downloading a file using AJAX, in which case you can find out when it finishes downloading. What is it.

JavaScript does not have direct access to files on the client computer for security reasons. The most you can see from your script is the file name.

+6
source

Firefox 3.5 DOM- XMLHttpRequest, , .

iframes , XMLHTTPRequest.

script, , NoSWFUpload. .

+4

Firefox 3 , , JavaScript, files array. , AJAX.

- W3, .

+3

.. -

function Upload() {

  var self = this;

  this.btnUpload;

  this.frmUpload;

  this.inputFile;

  this.divUploadArea;

  this.upload = function(event, target) {
    event.stopPropagation();

    if (!$('.upload-button').length) {
      return false;
    }

    if (!$('.form').length) {
      return false;
    }  

    self.btnUpload = target;
    self.frmUpload = $(self.btnUpload).parents('form:first');
    self.inputFile = $(self.btnUpload).prev('.upload-input');
    self.divUploadArea = $(self.btnUpload).next('.uploaded-area');

    var target = $(self.frmUpload).attr('target');
    var action = $(self.frmUpload).attr('action');

    $(self.frmUpload).attr('target', 'upload_target'); //change the form target to the iframe id
    $(self.frmUpload).attr('action', '/trnUpload/upload'); //change the form action to the upload iframe function page
    $(self.frmUpload).parent("div").prepend(self.iframe);

    $('#upload_target').load(function(event){

      if (!$("#upload_target").contents().find('.upload-success:first').length) {
        $('#upload_target').remove();
        return false;
      } else if($("#upload_target").contents().find('.upload-success:first') == 'false') {
        $('#upload_target').remove();
        return false;  
      }

      var fid = $("#upload_target").contents().find('.fid:first').html();
      var filename = $("#upload_target").contents().find('.filename:first').html();
      var filetype = $("#upload_target").contents().find('.filetype:first').html();
      var filesize = $("#upload_target").contents().find('.filesize:first').html();

      $(self.frmUpload).attr('target', target); //change the form target to the iframe id
      $(self.frmUpload).attr('action', action); //change the form  
      $('#upload_target').remove();

      self.insertUploadLink(fid, filename, filetype, filesize);
    });

  };

  this.iframe = '' +
                'false' +
                '';

  this.insertUploadLink = function (fid, filename, filetype, filesize) {
    $('#upload-value').attr('value', fid);

  }

}

$(document).ready(event) {
  var myupload = new Upload();  
  myupload.upload(event, event.target);
}

PHP APC , , ( jQuery, ). PHP , iframe, .

These are hacks. You will need to spend a lot of time to make it work. You will need administrator access to any server on which you want to run it so that you can install APC. You will also need to customize the HTML form corresponding to the js Upload class. A link to how to do this can be found here http://www.ultramegatech.com/blog/2008/12/creating-upload-progress-bar-php/

0
source

Source: https://habr.com/ru/post/1716775/


All Articles