Comment 0 for bug 347

Revision history for this message
Dafydd Harries (daf) wrote :

Uploading a file to the Librarian looks like this with the current API:

    file_id, file_alias = uploader.addFile(
        name=filename,
        size=size,
        file=filehandle,
        contentType='application/octet-stream')

The Librarian reads the file from the provided filehandle. However, if the code that's producing the file is oriented towards writing it to a file-like object, the file must be stored in a temporary location and its size calculated before the upload can be done.

I have some code that does just that:

    filehandle = tempfile.TemporaryFile()
    exporter.export_tarball_to_file(filehandle)
    size = filehandle.tell()
    filehandle.seek(0)

It would be nice if the Librarian would allow me to just do something like this:

    filehandle = uploader.uploadFilehandleFrob(
        name=filename,
        contentType='application/octet-stream')
    exporter.export_tarball_to_file(filehandle)

I'd imagine this is a fairly common use case.