Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get real path of local file? #6

Closed
zyhwhu2009 opened this issue Dec 20, 2018 · 4 comments
Closed

How can I get real path of local file? #6

zyhwhu2009 opened this issue Dec 20, 2018 · 4 comments

Comments

@zyhwhu2009
Copy link

Hi,
Very nice tool! I use ell first and now try to use wuy, and I think it's more convenient and powerful.
How can I get real path of local file by in html?
Thanks.

@manatlan
Copy link
Owner

manatlan commented Dec 20, 2018 via email

@zyhwhu2009
Copy link
Author

Thank you for your prompt reply. I am new and still do not know how to create a rpc method serverside. could you give me a example or reference.
btw, how could I upload a file as a server mode? method emit?
Thanks!!!!

@manatlan
Copy link
Owner

Here is an exemple, for serverside mode (note that : it doesn't have sense in window mode, because client & server are on the same host)

that's a drag'n'drop example : drop a text file on the page, it will be sent to the server via the upload rpc method ;-)

if you want to do it with binary file, just replace with readAsDataURL ... and decode dataurl on serverside !

# -*- coding: utf-8 -*-
import wuy

class index(wuy.Server):
    """
    <script>
    function mydragover(e) {
        e.target.style.background = "red";
        e.preventDefault()
    }
    function mydragend(e) {
        e.target.style.background = "white";
    }
    function mydrop(e) {
        e.target.style.background = "white";
        for(var f of e.dataTransfer.files) {
            var reader = new FileReader();
            reader.onload = function (ee) {
                wuy.upload(f.name,ee.target.result)
            };
            // reader.readAsDataURL(f);
            reader.readAsText(f);
        }
        e.preventDefault()
    }
    </script>
    <body
        ondragover="mydragover(event)"
        ondragleave="mydragend(event)"
        ondragend="mydragend(event)"
        ondrop="mydrop(event)">drop on me</body>
    """

    def upload(self,name,content):
        # here, on server side : save the file 'name', with the text 'content',
        print("server:",name,content)

if __name__=="__main__":
    index()

@zyhwhu2009
Copy link
Author

help me a lot!!!
thanks very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants