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

Upload with file input, not dragDrop #167

Closed
allthetime opened this issue Oct 27, 2014 · 2 comments
Closed

Upload with file input, not dragDrop #167

allthetime opened this issue Oct 27, 2014 · 2 comments

Comments

@allthetime
Copy link

@allthetime allthetime commented Oct 27, 2014

I'm trying to get file uploads working with a file input instead of just drag and drop.

I noticed that dragDrop passes dropped files through some conversion and the files that end up getting sent to client.seed( FILES... are not file objects anymore but a specially constructed object that looks like this:

{
   buffer: Uint8Array[10100971]
   lastModifiedDate: Thu Mar 28 2013 15:34:50 GMT-0700 (PDT)
   name: "Fusion Of Sense And Earth.mp3"
   size: 10100971
   type: "audio/mp3"
}

How can I hookup a file input so that when you click on it and add a file it gets pushed through this same process and is able to be seeded?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Oct 29, 2014

You should be able to use WebTorrent with a file input like this:

var WebTorrent = require('webtorrent')
document.getElementById('files').addEventListener('change', handleFileSelect, false)

function handleFileSelect (evt) {
  var files = evt.target.files // FileList object

  client.seed(files, function (torrent) {
    console.log(torrent.infoHash)
  })
}  

The client.seed function accepts many common sources of file data, including File, FileList, Blob and Buffer types. Full list here: https://github.com/feross/webtorrent#clientseedinput-opts-function-onseed-torrent-

(Sidenote: It looks like you're using an older version of drag-drop. The current version, 2.0.0, doesn't return a custom object anymore, but a FileList, or a Buffer if you're requiring drag-drop/buffer)

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Nov 19, 2014

This was fixed in webtorrent a while ago, you can see a file input working with webtorrent on http://instant.io. :)

@feross feross closed this Nov 19, 2014
@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.