Uploaded image for project: 'Nuxeo Python Client'
  1. Nuxeo Python Client
  2. NXPY-178

Use a uniq ID for the S3 direct upload key

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.4.0
    • Fix Version/s: 3.0.0
    • Component/s: Upload

      Description

      Error

      The current implementation is using the blob name to compute the key:

      self.key = "{}/{}".format(s3_info["baseKey"].rstrip("/"), self.blob.name)
      

      This will break when the file name contains disallowed characters like parenthesis.

      Here is a code that should work (see the file name used):

      # file: test-s3.py
      from nuxeo.client import Nuxeo
      from nuxeo.models import FileBlob
      
      
      host = "SERVER"
      auth = ("USER", "PWD")
      server = Nuxeo(host=host, auth=auth)
      
      batch = server.uploads.batch(handler="s3")
      blob = FileBlob(".../fah-installer_7.6.13_x86_64 (1).mpkg.zip")
      batch.upload(blob)
      batch.complete()
      

      The script will fail at the batch.complete() call:

      Traceback (most recent call last):
        File "nuxeo/client.py", line 282, in request
          resp.raise_for_status()
        File ".../requests/models.py", line 941, in raise_for_status
          raise HTTPError(http_error_msg, response=self)
      requests.exceptions.HTTPError: 400 Client Error:  for url: SERVER/nuxeo/api/v1/upload/batchId-9008aa8c-1af8-4d15-a67d-cb6830bbd341/0/complete
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "test-s3.py", line 12, in <module>
          batch.complete()
        File "nuxeo/models.py", line 230, in complete
          return self.service.complete(self, **kwargs)
        File "nuxeo/uploads.py", line 305, in complete
          return self.client.request("POST", endpoint, data=params, **kwargs)
        File "nuxeo/client.py", line 285, in request
          raise self._handle_error(exc)
      nuxeo.exceptions.HTTPError: HTTPError(400), error: 'java.lang.IllegalArgumentException: Invalid key: fah-installer_7.6.13_x86_64 (1).mpkg.zip', server trace: None
      

      Fix

      Instead of using the blob name, a UID should be used (as it is done in Web UI):

      from uuid import uuid4
      
      self.key = "{}/{}".format(s3_info["baseKey"].rstrip("/"), uuid4())
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mschoentgen Mickaël Schoentgen
                Reporter:
                mschoentgen Mickaël Schoentgen
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours
                  2h