Giter Site home page Giter Site logo

uploadserver's People

Contributors

abbbe avatar densaugeo avatar lishoujun avatar marvinruder avatar nterysin avatar shuangye avatar simarmugattarov avatar theo543 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

uploadserver's Issues

Unsupported Method: PUT

Is put allowed as an http method for this?

Operation not supported: 501 Unsupported method ('PUT') (PUT)

Add “Validate token” button

Currently, the token is validated after the file is completely uploaded. When a large file is uploaded using a slow internet connection, this can take a while. When I then forgot to add the token or added a misspelled token, I need to upload the entire file again.

It would be helpful to have a button “Validate token” right next to the token input field that sends the token to the server, which then replies with either “200 Token is valid”, “200 No token necessary” or “403 Token is enabled on this server, and your token is wrong”. This way, I can quickly and easily check whether a file upload would be accepted by the server before I waste time uploading it with a wrong token.

I am willing to propose a PR if this feature if you are generally open for such a feature.

Please consider writing to target directory directly, i.e., no tmp file

I want to upload some large files (size in GB) to an external USB drive. I found that during file uploading, the external USB drive LED does not flash. The computer internal LED flashes instead.
I opened the macOS Activity Monitor, and selected the Python process. In "Open Files and Ports", I found that the uploaded file was saved as a tmp file in computer internal disk, like this
/private/var/folders/kr/pn0vp9sx703fhy8v8d6fm8b80000gn/T/tmpfcqc7li5
and then wrote to the external USB drive.
That is, one upload generates 2 file copies. It's OK for few small files, but it takes more time when uploading large files, and extra writing decreases the lifetime of computer internal disk (SSD).

I want to save the file directly to the external USB drive, without tmp files. Could you please consider this improvement? Thank you.

macOS 12.4 Monterey. Python 3.8.9
Intel i7 CPU, 32GB DDRAM.

Feature request: add an entry point to support pipx installation

Pipx is a tool made specifically for installing pip packages as global applications. It would be nice if uploadserver supports this installation method.

The following is the setup script that works on my local fork.

setup(
    # other arguments here...
    entry_points={
        'console_scripts': [
            'uploadserver = uploadserver:main',
        ]
    },
)

Error 404 - File not found

Hello! I cannot access the upload page, as I'm getting this error:

Screenshot from 2024-03-27 10-59-41

I tried using python3 -m uploadserver and python3 -m uploadserver --basic-auth-upload hello:world

Issue with systemd-journal-upload

I was trying to have a simple way to start a server to upload the logs from another target using uploadserver.

I can see the file being transferred and finished even, however the connection only ends when systemd-journal-upload fails with timeout. And the uploadsever crashes with following Traceback:

Exception occurred during processing of request from ('10.10.10.9', 48360)
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\socketserver.py", line 691, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\http\server.py", line 671, in __init__
    super().__init__(*args, **kwargs)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\socketserver.py", line 755, in __init__
    self.handle()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\http\server.py", line 436, in handle
    self.handle_one_request()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\http\server.py", line 424, in handle_one_request
    method()
    result = receive_upload(self)
             ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\APXX\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\uploadserver\__init__.py", line 159, in receive_upload
    if 'files' not in form:
       ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\cgi.py", line 584, in __contains__
    raise TypeError("not indexable")
TypeError: not indexable

Any ideas?

Make dark mode optional by adding command-line argument `--no-dark-mode`

The upload page offers a dark mode feature, whereas the directory lists do not. While many users may find the dark mode a nice gadget, I find it quite irritating when some pages of the same server are shown with light and other with dark background.

Since it is hardly possible to insert custom CSS into http.server’s directory list HTML code (and I tried), it might be useful to be able to turn that feature off completely, e.g. using the command-line argument mentioned above.

Preventing Illegal Upload

I use this lib in a mini work flow, and I think a token is necessary.
I will try to add a starting parameter as token in my fork.
If there is any progress, I will inform you in time.

Accept `file` in addition to `files`

PowerShell's UploadFile does a POST with the content in the parameter named file. It would be cool if your tool accepted this as well.

I was in a rush and so I made the following changes to get it working:

    if "files" not in form:
        if "file" not in form:
            return (http.HTTPStatus.BAD_REQUEST, 'Field "files" not found')

    try:
        fields = form["files"]
    except Exception:
        fields = form["file"]

Not sure if you are interested in this or not.

can't open from IPv4 + feature request: message "upload completed"

just installed, first of all, amazing project! i like it, it's super simple and is exactly what i need :)
for some reason python -m uploadserver doesn't work on ipv4 by default, only ipv6 works.
it doesn't work by going to 127.0.0.1 or if open it from another pc in lan.
i see that there is "bind option" and using that it works (0.0.0.0).
both uploadserver and http.server display this at start: Serving HTTP on :: port 8000 (http://[::]:8000/) ...
but http.server works also on ipv4.
it's a minor issue but it would be nice if you can fix it so that i don't need to add the extra argument bind.
Python version is: 3.9.0 on windows 10 64bit
i can see that browser is loading while uploading and it stops when finished but a message "upload completed" would be much better.

How to use upload server for PUT requests

linux@linux-ont:~$ python3 -m uploadserver -d upload_py_http/
File upload available at /upload
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
192.168.241.178 - - [25/Aug/2022 11:44:22] code 501, message Unsupported method ('PUT')
192.168.241.178 - - [25/Aug/2022 11:44:22] "PUT /upload HTTP/1.1" 501 -

I am trying to test a feature in my application which needs an upload server. I am using uploadserver for this purpose. The application uses PUT method to upload. But when I try I am getting unsupported method.
Could you please add support or suggest how to use it for PUT method?

New Feature Proposal: Publish Service Info with mDNS

Although uploadserver is simple enough, some non-computer science people still have trouble using it. E.g., they do not know how to find out a computer's IP address.
Besides, if the host running uploadserver uses the IP address assigned from a DHCP server, it's possible that it changes. It's not so friendly to type the IP address in the web browser's address bar every time.

One solution could be using mDNS to publish the service info. This is the option used by VLC player, and some other mobiles Apps that transfer files wirelessly. Say you want to upload some media files to VLC player on your iPad, without a data cable. VLC player allows you to access a short URL like http://ipad.local to upload files.

The dow side is that we have to use a 3rd-party lib like zeroconf, breaking the simplicity of uploadserver.

    parser.add_argument('--host', '-H', type=str,
        help='Host name used for mDNS publishing')
    ...
    if args.host:
        publish_service(args.host, args.port)

def publish_service(host, port):
    from zeroconf import ServiceInfo, Zeroconf
    domain = ".local"
    if not host.endswith(domain):
        host += domain
    addresses = [i[4][0] for i in socket.getaddrinfo(socket.gethostname(), None)]
    info = ServiceInfo("_http._tcp.local.",
                       "Upload Server._http._tcp.local.",
                       port=port,
                       parsed_addresses=addresses,
                       server=f"{host}.")
    zeroconf = Zeroconf()
    zeroconf.register_service(info)

Run uploadserver with -H option like -H up, and now you can access it with URL http://up.local:8000

Single quote vs Double quotes

Using single quote (') works well on GNU/Linux, but not in Windows.
What works in both OSs (Linux & Windows) is double quotes ("").

Maybe you can modify the examples.

CORS support

I'm trying to use this server from a page with some javascript on it, but I can't get past the CORS checks, because uploadserver doesn't acccept OPTIONS requests. Is it possible to use uploadserver from the browser, e.g. by letting it specify allowed clients on the command line?

Multiple files upload

I have it all correctly set for single files uploads but I would like to add a choice for multiple files uploads... is that possible with this library? Thank you!

Doesn't support upload of large files, due to buffering

When trying to upload a file larger than available memory, the process gets killed by the OOM handler (Linux).

This appears to be because the file is read entirely into memory before being written out to disk. If at all possible (given the constraints of the now-deprecated CGI module in use), the file should be streamed to disk as it is being received, in order to minimise memory usage.

leftovers in case of token mismatch

I have noticed that sometimes uploadserver leaves temporary files even if token does not match.

To reproduce:

abb@mc:~/ae0ohYee$ python3 -m pip install -U uploadserver
Requirement already up-to-date: uploadserver in /home/abb/.local/lib/python3.8/site-packages (4.0.0)

abb@mc:~/ae0ohYee$ ls -la
total 8
drwxr-xr-x  2 abb abb 4096 Feb 10 12:31 .
drwxr-xr-x 10 abb abb 4096 Feb 10 12:30 ..

abb@mc:~/ae0ohYee$ python3 -m uploadserver -t ae0ohYee
File upload available at /upload
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

In 2nd terminal:

abb@mc:~/ae0ohYee$ md5sum /tmp/uploadserver-test.txt
edb68e00f7d67e7872f7787220804482  /tmp/uploadserver-test.txt

abb@mc:~/ae0ohYee$ curl -X POST http://127.0.0.1:8000/upload -F 'files=@/tmp/uploadserver-test.txt' -F 'token=abrakadabra'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <title>Error response</title>
    </head>
    <body>
        <h1>Error response</h1>
        <p>Error code: 403</p>
        <p>Message: Token is enabled on this server, and your token is missing or wrong.</p>
        <p>Error code explanation: HTTPStatus.FORBIDDEN - Request forbidden -- authorization will not help.</p>
    </body>
</html>

Back to the 1st terminal:

127.0.0.1 - - [10/Feb/2023 12:31:35] Upload of "uploadserver-test.txt" rejected (bad token)
127.0.0.1 - - [10/Feb/2023 12:31:35] code 403, message Token is enabled on this server, and your token is missing or wrong
127.0.0.1 - - [10/Feb/2023 12:31:35] "POST /upload HTTP/1.1" 403 -
^C
Keyboard interrupt received, exiting.

abb@mc:~/ae0ohYee$ ls -la
total 12
drwxr-xr-x  2 abb abb 4096 Feb 10 12:31 .
drwxr-xr-x 10 abb abb 4096 Feb 10 12:30 ..
-rw-------  1 abb abb 1320 Feb 10 12:31 tmphhxeecw5

abb@mc:~/ae0ohYee$ md5sum tmphhxeecw5
edb68e00f7d67e7872f7787220804482  tmphhxeecw5

This behaviour does not appear on very short files, so I have uploaded the test file to sprunge to let you reproduce it.

abb@mc:~/ae0ohYee$ cat /tmp/uploadserver-test.txt | curl -F 'sprunge=<-' http://sprunge.us
http://sprunge.us/vymoVG

Progress bar

It would be nice to have progress bar. Especially when you need to upload larger files. Because me and my friends use it to upload mods that can have up to 2 GB and even more. ;) Also authentication to see data wouldn't be bad at all.

Upload from home page

It would be really nice if there's an "Upload" button on the home page instead of having to go to the /upload page.
Thank you for this useful module anyway.

Feature request: Option for UUID-based filename

Hello developers, I have found this software helpful, and hope that my needs may perhaps fit into your roadmap.

I would like to have an option for automatically renaming incoming files to UUID-based filenames.
This comes with some advantages:

  • Prevent filename collisions.
  • Erase potential sensitive info in the original filename.

Specifically...

  • --uuid: Enable UUID-based file naming, which converts example.tar.xz to c09f51d8-aeac-4d0f-9850-dff741756e09.tar.xz.
  • --uuid-bare: Similar to --uuid, but converts example.tar.xz to c09f51d8-aeac-4d0f-9850-dff741756e09.

If this feature is to be introduced, I would also like to recommend a few mini-features to come along with it:

  • Provide a Final-Full-Path response header.
  • In the /upload form page, generate an anchor with href set to the HTTP full path of the (renamed) file after successful upload.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.