2

Im following this documentation to implement an application that I pick a file with an input tag

<input id="upload" type="file" />

and im tyring to upload using web3 js :

 document.querySelector('input#upload').click();
    let inputElement = document.getElementById("upload");
    inputElement.addEventListener("change", handleFiles, false);
    function handleFiles() {
       let fileList = this.files; /* now you can work with the file list */
       definedFile = fileList[0];
       web3.bzz.upload({data: definedFile}) // could also be "directory" or "data"
                .then(console.log);
    }

The problem is , my return value is being false.

I've already tested my web3.bzz uploading a local file like :

web3.bzz.upload({
        path: "/path/to/my/file",      // path to data / file / directory
        kind: "directory",           // could also be "file" or "data"
        defaultFile: "/test.png"}) // optional, and only for kind === "directory"
        .then(function(hash){
            console.log("Uploaded :" , hash);
        })
        .catch(console.log);

and it worked beautifully.

It swarm able to upload buffered files?

  • Did you tried to use web3.bzz.upload({file: definedFile}) ? – Eduardo Pereira Oct 25 '17 at 21:48
  • @EduardoPereira yeap and didnt worked :( – Lucas Oliveira Oct 25 '17 at 23:07
  • are you sure this javascript is complete/correct? definedFile is set inside the function handleFiles, but your upload is called right after the function definition? – faboolous Oct 26 '17 at 2:21
  • @faboolous , you are right the code it's incorrect. Still, even when I call it on the function , didn't worked – Lucas Oliveira Oct 26 '17 at 9:11
  • Now I've got a new issue : node:4640) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): ReferenceError: document is not defined (node:4640) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. , so it's seems the function picker it's being called, but it's not being able to create the document. – Lucas Oliveira Oct 26 '17 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.