import React, { Component } from "react"; import classNames from "classnames"; import Dropzone from "react-dropzone"; import Reveal from "react-reveal/Reveal"; import { Button, UploadFile } from "../"; import { Deco3, Deco4, Deco5 } from "../../svg"; import "./HomeUpload.scss"; export default class HomeUpload extends Component { state = { files: [] }; handleDrop = async acceptedFiles => { this.setState({ files: [ ...acceptedFiles.map(file => { return { file, status: "uploading" }; }), ...this.state.files ] }); acceptedFiles.forEach(async file => { const url = `https://siasky.net/api/skyfile?filename=${file.name}`; const fd = new FormData(); fd.append("file", file); const onComplete = (status, skylink) => { this.setState(state => { const index = state.files.findIndex(f => f.file === file); return { files: [ ...state.files.slice(0, index), { ...state.files[index], status, url: `https://siasky.net/${skylink}` }, ...state.files.slice(index + 1) ] }; }); }; try { const response = await fetch(url, { method: "POST", body: fd, mode: "cors" }); const { skylink } = await response.json(); onComplete("complete", skylink); } catch (error) { onComplete("error"); } }); }; render() { return (
this.handleDrop(acceptedFiles)}> {({ getRootProps, getInputProps, isDragActive }) => ( <>
Drag & drop your file(s) here to pin
)}
{this.state.files.length > 0 && (
{this.state.files.map((file, i) => { return ; })}
)}

Once a file has been uploaded, a 46 byte link called a 'Skylink' is generated. That link can then be shared with anyone to fetch the file from Skynet.

); } }