```javascript! let fileInput = document.getElementById("upload"); fileInput.addEventListener("change", function (e) { try { const file = e.target.files[0]; if (!file) return; console.log(e.target.files[0].name); pubFileToS3(file) return file; } catch (error) { console.log("Catch Error: ", error); } }); const pubFileToS3 = async (File) => { const formData = new FormData() formData.append('bucket', File) const file = formData.get('bucket') const reader = new FileReader() reader.readAsDataURL(file) reader.onload = async(e) => { if (/^image\/[jpeg|png|gif]/.test(File.type)) { const payload = { "bucket": "upload", "object": File.name, "header": {"Content-Type": `${File.type}`}, "file": e.target.result } const reply = await webChatStore.mcSend( ">svc/s3", "s3://putObject", payload, ); console.log('reply', reply) const result = utils.resultHandle(reply); console.log(result.Data) } } } ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up