Load local data into IPython notebook server

烂漫一生 提交于 2019-11-30 07:34:12

Since you have jupyter installed, all users should see the files/folders in the jupyter startup directory as well as its subdirectory. The new button on the jupyter notebook can be used to create a new file/folder or even a terminal. Files can be uploaded using drag-drop or click here feature highlighted below.

volhv

An alternative way to achieve this with python:

def jupyter_upload(token, filePath, resourceDstPath, jupyterUrl='http://localhost:8888'):
    """
        Uploads File to Jupyter Notebook Server
        ----------------------------------------
        :param token:
            The authorization token issued by Jupyter for authentification 
            (enabled by default as of version 4.3.0)
        :param filePath:
            The file path to the local content to be uploaded

        :param resourceDstPath:
            The path where resource should be placed.
            The destination directory must exist.

        :param jupyterUrl:
            The url to the jupyter server. Default value is typical localhost installation.

        :return: server response

    """
    import os
    import base64
    import urllib
    import json
    import requests
    dstPath = urllib.quote(resourceDstPath)
    dstUrl = '%s/api/contents/%s' % (jupyterUrl, dstPath)
    fileName = filePath[1 + filePath.rfind(os.sep):]
    headers = {}
    headers['Authorization'] = 'token '+token
    with open(filePath, 'r') as myfile:
        data=myfile.read()
        b64data=base64.encodestring(data)
        body = json.dumps({
            'content':b64data,
            'name': fileName,
            'path': resourceDstPath,
            'format': 'base64',
            'type':'file'
        })
        return requests.put(dstUrl, data=body, headers=headers, verify=True)

If it is a text file, create a empty file, edit it and then copy/paste the content..

You can do this to bypass the 25mb constraint

Once you run jupyter ipython notebook, click on new --> Go to terminal and then simply run the following command :

You can pass your files url here and get your file uploaded on the server and you are ready to go. Otherwise directly drag a file or upload the file from the upload button.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!