Merge pull request #381 from NebulousLabs/code-samples
Update code samples for API v2
This commit is contained in:
commit
306a43aeba
|
@ -1,11 +1,14 @@
|
||||||
export const python = `import siaskynet
|
export const python = `import siaskynet as skynet
|
||||||
|
|
||||||
|
# create a client
|
||||||
|
client = skynet.SkynetClient()
|
||||||
|
|
||||||
# upload
|
# upload
|
||||||
skylink = siaskynet.upload_file("./src.jpg")
|
skylink = client.upload_file("./src.jpg")
|
||||||
print("Upload successful, skylink: " + skylink)
|
print("Upload successful, skylink: " + skylink)
|
||||||
|
|
||||||
# download
|
# download
|
||||||
siaskynet.download_file("./dst.jpg", skylink)
|
client.download_file("./dst.jpg", skylink)
|
||||||
print("Download successful")`;
|
print("Download successful")`;
|
||||||
|
|
||||||
export const curl = `# upload
|
export const curl = `# upload
|
||||||
|
@ -14,22 +17,18 @@ curl -X POST "https://siasky.net/skynet/skyfile" -F file=@src.jpg
|
||||||
# download
|
# download
|
||||||
curl "https://siasky.net/[skylink]" -o dst.jpg`;
|
curl "https://siasky.net/[skylink]" -o dst.jpg`;
|
||||||
|
|
||||||
export const node = `const skynet = require('@nebulous/skynet');
|
export const node = `const { SkynetClient } = require('@nebulous/skynet');
|
||||||
|
|
||||||
|
// create a client
|
||||||
|
const client = new SkynetClient();
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// upload
|
// upload
|
||||||
const skylink = await skynet.UploadFile(
|
const skylink = await client.UploadFile("./src.jpg");
|
||||||
"./src.jpg",
|
|
||||||
skynet.DefaultUploadOptions
|
|
||||||
);
|
|
||||||
console.log(\`Upload successful, skylink: \${skylink}\`);
|
console.log(\`Upload successful, skylink: \${skylink}\`);
|
||||||
|
|
||||||
// download
|
// download
|
||||||
await skynet.DownloadFile(
|
await client.DownloadFile("./dst.jpg", skylink);
|
||||||
"./dst.jpg",
|
|
||||||
skylink,
|
|
||||||
skynet.DefaultDownloadOptions
|
|
||||||
);
|
|
||||||
console.log('Download successful');
|
console.log('Download successful');
|
||||||
})()`;
|
})()`;
|
||||||
|
|
||||||
|
@ -39,21 +38,21 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
skynet "github.com/NebulousLabs/go-skynet"
|
skynet "github.com/NebulousLabs/go-skynet"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var client = skynet.New()
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// upload
|
// upload
|
||||||
skylink, err := skynet.UploadFile("./src.jpg", skynet.DefaultUploadOptions)
|
skylink, err := client.UploadFile("./src.jpg", skynet.DefaultUploadOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Unable to upload: %v", err.Error())
|
panic("Unable to upload: " + err.Error())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
fmt.Printf("Upload successful, skylink: %v\\n", skylink)
|
fmt.Printf("Upload successful, skylink: %v\\n", skylink)
|
||||||
|
|
||||||
// download
|
// download
|
||||||
err = skynet.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions)
|
err = client.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Something went wrong, please try again.\\nError: %v", err.Error())
|
panic("Something went wrong, please try again.\\nError: " + err.Error())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
fmt.Println("Download successful")
|
fmt.Println("Download successful")
|
||||||
}`;
|
}`;
|
||||||
|
|
Reference in New Issue