Open mgpeng opened 6 years ago
Hi again!
No worries, it's not an old version, the README is just not up to date. As mentioned in the other issue, this is more of a preview of what is to come for third party devs, not yet meant as a ready to use library. There are still going to be changes in how this lib will be used. The goal is to get something similar to what axios is doing.
For now, to use the download in the browser, use Download.toBlob(handle, options)
, for Uploads it's Upload.fromFile(file, options)
where file
is a File object.
For node there's Download.toBuffer(handle, options)
and Upload.fromData(buffer, filename, options)
(which also works in the browser with Uint8Array
if you don't want to use File objects)
The rest still mostly applies.
Keep in mind these methods are most likely temporary.
Glad to see you got this far! Keep the questions coming if you get stuck.
Hi, nullpilot
download work fine, but upload have error
do:
let upload = new Upload.fromData(fileBuffer, upfilename);
error:
~/learn-oyster/oyster-streamable/dist/upload.js:182
throw "Missing required keys: " + invalidKeys.join(",");
^
Missing required keys: alpha,beta,epochs
nullpoint has any advice ?
Heya, sorry for not seeing this earlier.
One thing is that you can skip the new
keyword, fromData
and the rest are static functions, not constructors. For the missing options, Aaron needs to chime in, I didn't have a chance to have a closer look at these changes yet.
@AaronVasquez can you have a look at this? I couldn't really get the correct syntax for the call from the webinterface implementation.
That error is thrown when the call to fromData
/fromFile
doesn't have the required config properties set. See below as an example.
Stream.Upload.fromFile(file, {
alpha: "https://broker-1.oysternodes.com",
beta: "https://broker-2.oysternodes.com",
epochs: 1,
iotaProvider: new IOTA({ provider: "https://poll.oysternodes.com" }) // please use this for just reads to IOTA.
});
Thanks nullpilot and AaronVasquez, now upload and download work fine on nodejs for download:
import Download from "./download";
const fs = require('fs');
let pathprefix = 'updownfiles/';
var handle ='****************************b608dc*****************';
let download = Download.toBuffer(handle);
download.on('meta', metadata => {
// {fileName: "oyster.txt", ext: "txt", numberOfChunks: 2}
});
download.on('finish', filedata => {
let path = pathprefix + filedata.metadata.fileName;
let bufferFile = filedata.result;
fs.writeFile(path,bufferFile,(err) => {
if (err){
throw 'could make this file' + err;
}
console.log('Saved download file');
});
// {file: Blob(), metadata: {…}, target: Download}
});
for upload:
import Upload from "./upload";
import IOTA from "iota.lib.js";
const fs = require('fs');
let uppathprefix = 'updownfiles/';
let upfilename = 'learnSome.js';
fs.readFile(uppathprefix+upfilename , function(err,bufferFile){
if (err) {
console.log('Error:- ' + err);
throw err;
}
let upload = Upload.fromData(bufferFile, upfilename, {
alpha: "https://broker-1.oysternodes.com",
beta: "https://broker-2.oysternodes.com",
epochs: 1,
iotaProvider: new IOTA({ provider: "https://poll.oysternodes.com" }) // please use this for just reads to IOTA.
});
upload.on('invoice', invoice => {
console.log(invoice)
// {address: "<ETH_ADDRESS>", cost: 20}
});
upload.on('finish', filedata => {
console.log(filedata)
// {handle: "<OYSTER_HANDLE>", metadata: {…}, target: Upload}
});
});
I think we need more complex download and upload features, like upload folder, upload one file to specific folder position, download folder structure, download whole folder, one folder with only one handle (not every file has one handle), and few different person share one file or one folder, delete file limitation( maybe can set never be deleted or after few years can be deleted). Do you have plan for those features? or have you better idea?
I clone this repo on local and write simple js file to test download file which I send through oyster storage website, I got error when run this file:
check download.js found to seems "targetStream" is actually not constructor:
do I clone old version? I clone master