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

Use Python to upload without saving locally? #94

Open
hiven opened this issue Apr 15, 2024 · 1 comment
Open

Use Python to upload without saving locally? #94

hiven opened this issue Apr 15, 2024 · 1 comment

Comments

@hiven
Copy link

hiven commented Apr 15, 2024

Do I really have to save my file locally to use TUS?

The code:

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return jsonify({'error': 'No file part'})

    file = request.files['file']
    if file.filename == '':
        return jsonify({'error': 'No selected file'})

    tus_client = client.TusClient('http://tusd.tusdemo.net/files/')
    uploader = tus_client.uploader(file.stream, chunk_size=200)

    try:
        # Upload the entire file
        upload_response = uploader.upload()
        file_url = upload_response.headers['Location']
        return jsonify({'file_url': file_url})
    except Exception as e:
        return jsonify({'error': str(e)})

The error:
TypeError: stat: path should be string, bytes, os.PathLike or integer, not SpooledTemporaryFile

@Acconut
Copy link
Member

Acconut commented Apr 17, 2024

Yes, right now uploads with tus-py-client must be backed by a file on disk, so the client can seek around and resume the upload if necessary.

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