alican / django-tus

Django app implementing server side of tus protocol to powering resumable file uploads for django projects. More Info about: http://tus.io/
MIT License
49 stars 32 forks source link

Does this project actually work out of the box? #35

Closed skinkie closed 1 year ago

skinkie commented 1 year ago

I would like to reference the following issue.

https://github.com/alican/django-tus-example/issues/1

When I try this as first time user, I notice the same issue as described there. Offset being wrong, only the final part of the file written. I have noticed that upgrading the client library does not have any (positive) effect.

skinkie commented 1 year ago

From my current observation is (under Linux) the behaviour that mode 'wb' would always create a 'new file'. When I instead change the code to use wb and r+b I am able to get 'almost' the same output. The almost in this case has a \0 byte on the end which I have not yet able to track the origin from.

    def _write_file(self, path, offset, content, mode="r+b"):
        with open(path, mode) as f:
            outfile = File(f)
            outfile.seek(offset)
            outfile.write(content)

    def write_init_file(self):
        try:
            self._write_file(self.get_path(), self.file_size, b"\0", "wb")
        except IOError as e:
            error_message = "Unable to create file: {}".format(e)
            logger.error(error_message, exc_info=True)
            return TusResponse(status=500, reason=error_message)

    def write_chunk(self, chunk):
        try:
            self._write_file(self.get_path(), chunk.offset, chunk.content, "r+b")
            self.offset = cache.incr("tus-uploads/{}/offset".format(self.resource_id), chunk.chunk_size)
skinkie commented 1 year ago

Conclusion: github is up to date, but no (new) release has been published.