Created
April 28, 2019 14:06
-
-
Save oeway/19426ba9ead4db034c4ee203da64cdab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<docs lang="markdown"> | |
[TODO: write documentation for this plugin.] | |
</docs> | |
<config lang="json"> | |
{ | |
"name": "FileUploadDownloadDemo", | |
"type": "window", | |
"tags": [], | |
"ui": "", | |
"version": "0.1.0", | |
"cover": "", | |
"description": "[TODO: describe this plugin with one sentence.]", | |
"icon": "extension", | |
"inputs": null, | |
"outputs": null, | |
"api_version": "0.1.3", | |
"env": "", | |
"requirements": [], | |
"dependencies": [], | |
"defaults": {"w": 20, "h": 10} | |
} | |
</config> | |
<script lang="javascript"> | |
class ImJoyPlugin { | |
async setup() { | |
api.log('initialized') | |
} | |
async run(ctx) { | |
window.upload = async ()=>{ | |
const url = await api.requestUploadUrl({engine: 'http://127.0.0.1:9527', overwrite: true}) | |
const imageFile = document.getElementById('file').files[0] | |
const fileInfo = await api.uploadFileToUrl({file:imageFile, url: url}) | |
api.alert('file uploaded.') | |
console.log('response', fileInfo) | |
const durl = await api.getFileUrl({engine: 'http://127.0.0.1:9527', path: fileInfo.path }) | |
const response = await api.downloadFileFromUrl({url: durl}) | |
console.log('downloaded ', response) | |
api.alert('file downloaded.') | |
} | |
} | |
} | |
api.export(new ImJoyPlugin()) | |
</script> | |
<window lang="html"> | |
<div> | |
<p> | |
<p id='output'></p> | |
<input id="file" name="file" type="file" value=""/> | |
<button onclick="upload()">upload</button> | |
</p> | |
</div> | |
</window> | |
<style lang="css"> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment