This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/packages/webapp/src/components/CodeExamples/Code.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

export const curl = `# upload
curl -X POST "https://siasky.net/skynet/skyfile" -F file=@src.jpg
# download
curl "https://siasky.net/[skylink]" -o dst.jpg`;
export const browserjs = `import { SkynetClient } from "skynet-js";
// create a client
const client = new SkynetClient();
// Assume we have a file from an input form.
async function example() {
try {
// upload
const { skylink } = await client.uploadFile(file);
console.log(\`Upload successful, skylink: \${skylink}\`);
// download
await client.downloadFile(skylink);
console.log('Download successful');
} catch (error) {
console.log(error)
}
}`;
2020-09-07 15:32:25 +00:00
export const python = `import siaskynet as skynet
# create a client
client = skynet.SkynetClient()
# upload
2020-09-07 15:32:25 +00:00
skylink = client.upload_file("./src.jpg")
print("Upload successful, skylink: " + skylink)
# download
2020-09-07 15:32:25 +00:00
client.download_file("./dst.jpg", skylink)
2020-02-18 16:25:03 +00:00
print("Download successful")`;
2020-09-07 15:32:25 +00:00
export const node = `const { SkynetClient } = require('@nebulous/skynet');
// create a client
const client = new SkynetClient();
(async () => {
// upload
2020-09-07 15:32:25 +00:00
const skylink = await client.UploadFile("./src.jpg");
console.log(\`Upload successful, skylink: \${skylink}\`);
2020-09-07 15:32:25 +00:00
// download
2020-09-07 15:32:25 +00:00
await client.DownloadFile("./dst.jpg", skylink);
console.log('Download successful');
2020-02-18 16:25:03 +00:00
})()`;
export const go = `package main
import (
"fmt"
2020-09-24 15:00:51 +00:00
skynet "github.com/NebulousLabs/go-skynet/v2"
)
2020-09-07 15:32:25 +00:00
// create a client
2020-09-07 15:32:25 +00:00
var client = skynet.New()
func main() {
// upload
2020-09-07 15:32:25 +00:00
skylink, err := client.UploadFile("./src.jpg", skynet.DefaultUploadOptions)
if err != nil {
2020-09-08 14:53:05 +00:00
panic("Unable to upload: " + err.Error())
}
fmt.Printf("Upload successful, skylink: %v\\n", skylink)
// download
2020-09-07 15:32:25 +00:00
err = client.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions)
if err != nil {
2020-09-08 14:53:05 +00:00
panic("Something went wrong, please try again.\\nError: " + err.Error())
}
fmt.Println("Download successful")
2020-02-18 16:25:03 +00:00
}`;