Files

To Share and +4 nLEARNs

import {WidgetEditor} from "@site/src/components/social-widget"

Files is a built-in component that enables to input files with drag and drop support. To use this feature, simply use the Files component. This component is a dependency from the IpfsImageUpload component.

Read more about the Files component here.


Example

“`ts
State.init({ img: null });

const uploadFileUpdateState = (body) => {
asyncFetch(
“https://ipfs.near.social/add”,
{
method: “POST”,
headers: { Accept: “application/json” },
body
}
).then(
(res) => {
const cid = res.body.cid;
State.update({ img: { cid } });
}
)
};

const filesOnChange = (files) => {
if (files) {
State.update({ img: { uploading: true, cid: null } });
uploadFileUpdateState(files[0]);
}
};

return (

{ state.img?
upload preview
: “”
}

{ state.img?.uploading ? Uploading > : “Upload an Image” }

);
“`

Generate comment with AI 2 nL
Scroll to Top
Report a bug👀