Librarian should have a write API for uploads

Bug #347 reported by Dafydd Harries on 2005-04-11
4
Affects Status Importance Assigned to Milestone
Launchpad itself
Low
Unassigned

Bug Description

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.

Stuart Bishop (stub) wrote :

So far, all the cases I've seen have had the size available - either form uploads, being read from the filesystem, or small files with content in a string.

As you have use cases, this could be implemented as a class in librarian/client.py:

class Something:
    def __init__(self):
        [open a temporary file]
    def write(self, data):
        [write data to temporary file]
    def close(self):
        [upload the contents of the temporary file to the librarian]
        [set an attribute to the newly created libraryfilealias id]

Dafydd Harries (daf) on 2005-12-16
Changed in launchpad:
status: New → Accepted
Christian Reis (kiko) on 2006-09-23
description: updated

Christian Reis wrote:

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

The only use case I've heard about so far.

I don't know if this would be very helpful - code uploading to the
Librarian should be handling upload failure exceptions gracefully. If the
Librarian client provided an API to hand out an open file like object, the
developer would need to remember to do this handling around whatever code is
invoking the close() method on that file like object.

--
Stuart Bishop <email address hidden> http://www.canonical.com/
Canonical Ltd. http://www.ubuntu.com/

Curtis Hovey (sinzui) on 2010-06-02
visibility: private → public
Stuart Bishop (stub) on 2010-06-03
Changed in launchpad-foundations:
status: Triaged → Won't Fix
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers