Uploading files

Answered
New post

Comments

3 comments

  • Official comment
    Alex Novotny

    Hello, 

    Have you tried something like this post from Stack Overflow? 

    Thanks, 

    Alex, Box Developer Advocate

    Comment actions Permalink
  • Alex Novotny

    It does look like our sdk example only shows a file path... Ill send this to that team too. 

    Alex

    0
    Comment actions Permalink
  • Kamil Berdychowski

    Hi takuya akama,

    I'll preparing an update to the docs, here is something that worked for me when I wanted to upload a base64 content using Box Node SDK

    var {Readable, ReadableOptions} = require('stream');
    var fs = require('fs');
    var base64Content = 'TXkgY29udGVudAo='; // your base64 content
    var base64Buffer = Buffer.from(base64Content, 'base64');
    // we are using just Readable to create a stream, but you can use any library you want
    var stream = new Readable()
    stream._read = () => {
    stream.push(base64Buffer);
    stream.push(null);
    };
    // you have to pass options and define content length
    var options = {
    content_length: Buffer.byteLength(base64Content, 'base64')
    };
    // I'm uploading file to my root folder to a file 'My Base64 File.txt'
    client.files.uploadFile('0', 'My Base64 File.txt', stream, options);
    0
    Comment actions Permalink

Please sign in to leave a comment.