Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't send blob file #540

Closed
JenGL opened this issue Jun 22, 2019 · 18 comments
Closed

Can't send blob file #540

JenGL opened this issue Jun 22, 2019 · 18 comments
Assignees
Milestone

Comments

@JenGL
Copy link

JenGL commented Jun 22, 2019

I'm trying to send a file drag and dropped in a div, but i always get this error.
Error: Type "function Blob() { [native code] }" not yet supported.

sendFiles(fileList) {
    Array.from(fileList).forEach(file => {
        const blob = new Blob([file], { type: file.type });
        this.conn.send({
          op: operation.FILE,
          file: blob,
          filename: file.name,
          filetype: file.type
        });
    });
  }

I tryed to send directly File Object, Blob or ArrayBuffer. Got always the same error

@kidandcat
Copy link
Member

kidandcat commented Jun 23, 2019

Convert it to base64, binary data seems to not be supported yet.

@JenGL
Copy link
Author

JenGL commented Jun 23, 2019

I found a lot of posts on internet that use peerjs to send blob.
like here: https://blog.bitsrc.io/use-webrtc-and-peerjs-to-build-an-image-sharing-app-f8163b6a6266
or here: https://www.sitepoint.com/file-sharing-component-react/

may be it was working on older release ?

@kidandcat
Copy link
Member

kidandcat commented Jun 24, 2019

Which browsers are you using? Give me versions please

@JenGL
Copy link
Author

JenGL commented Jun 25, 2019

last Chrome version: Version 75.0.3770.100 (official Build) (64 bit)

@kidandcat
Copy link
Member

Sorry, I re-read your first message. The error "Error: Type "function Blob() { [native code] }" not yet supported." looks like is not related at all to WebRTC. Could you paste more code? if it is private, you can write me an email instead kidandcat@gmail.com

@JenGL
Copy link
Author

JenGL commented Jun 27, 2019

this is the onDrop handler (drag and drop any file in a div)

onDrop(evt) {
        const el = evt.target;
        el.classList.remove("drop_here");
        this.peer.sendFiles(evt.dataTransfer.files);
        evt.preventDefault();
        evt.stopPropagation();
        return false;
      }

this is the sendFiles() implementation

sendFiles(fileList) {
    Array.from(fileList).forEach(file => {
        const blob = new Blob([file], { type: file.type });
       // const blob = file; <- tried this too given that file is a blob
        this.conn.send({                  // this.conn is a workin connection to another peer
                                                     // this.conn.send("hi") here correctly working
          op: operation.FILE,
          file: blob,
          filename: file.name,
          filetype: file.type
        });
    });
  }

Can't share more code atm, if you need more i'll try to replicate in a jsfiddle

@kidandcat
Copy link
Member

Do you get the exac "Error: Type "function Blob() { [native code] }" not yet supported." error if you try sending the File directly? (without calling Blob constructor)

@JenGL
Copy link
Author

JenGL commented Jun 28, 2019

receiver fiddle: https://jsfiddle.net/ygeb5093/
sender fiddle: https://jsfiddle.net/vg14skj8/

File or Blob object throws the same error yes.

@RealHandy
Copy link

RealHandy commented Jun 30, 2019

Could you be having this issue? #536
If so, you can see the place where I patched it in js-binarypack here: binaryjs/js-binarypack#13

@JenGL
Copy link
Author

JenGL commented Jul 1, 2019

y it's probably the same issue.

@afrokick
Copy link
Member

afrokick commented Jul 9, 2019

@RealHandy I had create new pull request to our fork peers/js-binarypack#7
We'll use our fork in PeerJS

@JenGL
Copy link
Author

JenGL commented Jul 9, 2019

@afrokick if you are going to update the PeerJS v1 can you also add this patch : #347

@afrokick
Copy link
Member

afrokick commented Jul 9, 2019

@afrokick if you are going to update the PeerJS v1 can you also add this patch : #347

could you please create pr? I'll merge it

@JenGL
Copy link
Author

JenGL commented Jul 9, 2019

done: #550

@JenGL
Copy link
Author

JenGL commented Jul 25, 2019

@afrokick Blob problem is present also in v1.0.2
receiver: https://jsfiddle.net/rjno0sz8/
sender: https://jsfiddle.net/po5xyhk7/

error: peerjs.min.js:4 Uncaught Error: Type "function Blob() { [native code] }" not yet supported
    at n.pack (peerjs.min.js:4)
    at n.pack_object (peerjs.min.js:4)
    at n.pack (peerjs.min.js:4)
    at Function.pack (peerjs.min.js:4)
    at u.send (peerjs.min.js:30)
    at u._sendChunks (peerjs.min.js:30)
    at u.send (peerjs.min.js:30)
    at HTMLDivElement.<anonymous> ((index):61)

@afrokick
Copy link
Member

We didn't fix it in 1.0.2, only #550

@JenGL could you please help us with fix it via pr?

@JenGL
Copy link
Author

JenGL commented Jul 26, 2019

@RealHandy I had create new pull request to our fork peers/js-binarypack#7
We'll use our fork in PeerJS

Shouldn't this fix that problem ?

@JenGL
Copy link
Author

JenGL commented Jul 26, 2019

I create two different pr: one for the fork of bynarypacker-js and anotherone for the peerjs with the update lib (I had to copy the builded js lib inside peerjs)
binaryjs/js-binarypack#16
#560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants