Uploading files
回答済みIf you want to use node.js to upload a file to the box, use
However, if I want to upload base64 data instead of a file path, what should I do?
Also, the fileType can be String or binary, but if binary, which buffer?
Please let me know.
-
正式なコメント
Hello,
Have you tried something like this post from Stack Overflow?
Thanks,
Alex, Box Developer Advocate
コメントアクション -
It does look like our sdk example only shows a file path... Ill send this to that team too.
Alex
-
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);
サインインしてコメントを残してください。
コメント
3件のコメント