title: How to perform actions on files stored in S3 bucket?
body: <p>In a Django-based web sevrice I'm implementing storage for <code>FileField</code> objects in S3 bucket. Some of those files later are copied to temporary path in the service itself, generate some result archive and are instantly deleted from temporary storage.</p>
  
  <p>Here's simplified version of one of models I have:</p>
  
  <pre><code>class MyModel(models.Model):
      some_image = models.ImageField(storage=PrivateMediaStorage())
      some_file = models.FileField(storage=PrivateMediaStorage())
      ...
  </code></pre>
  
  <p>Where <code>PrivateMediaStorage</code> is very primitive <code>S3Boto3Storage</code> implementation:</p>
  
  <pre><code>class PrivateMediaStorage(S3Boto3Storage):
      location = 'private'
      default_acl = 'private'
      file_overwrite = False
      custom_domain = False
  </code></pre>
  
  <p>With this implmenetation files are being correctly uploaded to <code>S3</code> bucket. </p>
  
  <p>At some point when service wants to use them (copy to temporary local storage):</p>
  
  <pre><code>instance = MyModel.objects.get(...)
  shutil.copy2(instance.some_image.name, ***some_temporary_path_at_the_server***)
  shutil.copy2(instance.some_file.name, ***some_temporary_path_at_the_server***)
  </code></pre>
  
  <p>This action raises <code>FileNotFound</code> exception:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
      response = get_response(request)
    File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
      return view_func(*args, **kwargs)
    File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
      return self.dispatch(request, *args, **kwargs)
    File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch
      response = self.handle_exception(exc)
    File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception
      self.raise_uncaught_exception(exc)
    File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
      raise exc
    File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
      response = handler(request, *args, **kwargs)
    File "/code/api/views.py", line 55, in get
      configuration.content_json.name,
    File "/code/passmaster/compressor.py", line 16, in __init__
      self.temporary_directory, self.temporary_path = self.create_temporary_path(*args, **kwargs)
    File "/code/passmaster/compressor.py", line 28, in create_temporary_path
      shutil.copy2(file, temporary_path)
    File "/usr/local/lib/python3.7/shutil.py", line 266, in copy2
      copyfile(src, dst, follow_symlinks=follow_symlinks)
    File "/usr/local/lib/python3.7/shutil.py", line 120, in copyfile
      with open(src, 'rb') as fsrc:
  FileNotFoundError: [Errno 2] No such file or directory: 'some_image_JkaNI0p.png'
  [31/Dec/2019 10:54:33] "GET /v1/dummy-pass HTTP/1.1" 500 104554
  </code></pre>
  
  <p>Why is this happening and did I make a mistake in storage implementation or rather refer file paths incorrectly?</p>
  
  <hr>
  
  <p>Side question:</p>
  
  <p>From other related questions I already found out that <code>S3Boto3Storage</code> <a href="https://stackoverflow.com/questions/48785235/django-user-uploaded-s3-files-in-the-view">does not provide</a> <code>.path()</code> method. I'm using both local and <code>S3</code> storages depending on whether I'm running local development env or deploying code to heroku. Is there a common pattern which can be used to address file path that works for both local and <code>S3</code> storage implementations?</p>