Skip to content

[XmlHttpRequest] xhr.upload.onprogress not working with xhr.send({uri: 'file:///...'}) #15724

@1stman

Description

@1stman

I think, it's a bug

I'm trying to upload video with youtube v3 API, looking on this example.

So, I wrote something like this:

var xhr = new XMLHttpRequest();
xhr.open('PUT', this.url, true);
xhr.setRequestHeader('Content-Type', this.contentType); <=== video/mp4
xhr.setRequestHeader('Content-Range', 'bytes ' + this.offset + '-' + (end - 1) + '/' + this.filesize);
xhr.setRequestHeader('X-Upload-Content-Type', this.filetype);  <=== video/mp4

if (xhr.upload) {
  xhr.upload.addEventListener('progress', this.onProgress);
}
xhr.onload = this.onContentUploadSuccess_.bind(this);
xhr.onerror = this.onContentUploadError_.bind(this);
xhr.send({uri: this.file.path});  <=== file:///.....

and it works, i have xhr.onload and xhr.onerror and video file is uploaded to youtube and played there.

But i haven't xhr.upload.onprogress.

I try xhr.onprogress, xhr.upload.onprogress, xhr.upload.addEventListener - all of this not works.

BUT!
When i use FormData

let data = new FormData();
data.append('File', {
      uri:  source.path,
      type: source.type,
      name: source.name
});
var xhr = new XMLHttpRequest();
  xhr.open('PUT', this.url, true);
  //xhr.setRequestHeader('Content-Type', this.contentType);  
  //=== comment this, because it throw error 'multipart != video/mp4'
  //xhr.setRequestHeader('Content-Range', 'bytes ' + this.offset + '-' + (end - 1) + '/' + this.filesize);
  //=== comment this, because sending data size != filesize
  xhr.setRequestHeader('X-Upload-Content-Type', this.filetype);

  if (xhr.upload) {
    xhr.upload.addEventListener('progress', this.onProgress);
  }
  xhr.onload = this.onContentUploadSuccess_.bind(this);
  xhr.onerror = this.onContentUploadError_.bind(this);
  xhr.send(data); <==== FormData

xhr.upload.onprogress is working. But then youtube api return processing error, because it support only 'video/*' and 'application/octet-stream' and does not support 'multipart/form-data'.

What I do wrong and what I need to do for using xhr.upload.onprogress WITHOUT FormData?

P.S. sorry for my ugly english

  1. react-native v0.47.2:
  2. node v8.2.1:
  3. npm v5.3.0:
  • Target Platform: Android
  • Development Operating System: MacOS
  • Build tools: Android SDK

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions