parameters: (self, uploaded_file, cache_break=False)
docstring: Given a file uploaded by a user, create a Capture record and warc.
docstring_summary: Given a file uploaded by a user, create a Capture record and warc.
docstring_tokens: Given a file uploaded by a user create a Capture record and warc .
function: def write_uploaded_file(self, uploaded_file, cache_break=False):
          """
              Given a file uploaded by a user, create a Capture record and warc.
          """
          from api.utils import get_mime_type, mime_type_lookup  # local import to avoid circular import
  
          # normalize file name to upload.jpg, upload.png, upload.gif, or upload.pdf
          mime_type = get_mime_type(uploaded_file.name)
          file_name = f'upload.{mime_type_lookup[mime_type]["new_extension"]}'
          warc_url = f"file:///{self.guid}/{file_name}"
  
          # append a random number to warc_url if we're replacing a file, to avoid browser cache
          if cache_break:
              r = random.SystemRandom()
              warc_url += f"?version={str(r.random()).replace('.', '')}"
  
          capture = Capture(link=self,
                            role='primary',
                            status='success',
                            record_type='resource',
                            user_upload='True',
                            content_type=mime_type,
                            url=warc_url)
          warc_size = []  # pass a mutable container to the context manager, so that it can populate it with the size of the finished warc
          with preserve_perma_warc(self.guid, self.creation_timestamp, self.warc_storage_file(), warc_size) as warc:
              uploaded_file.file.seek(0)
              write_resource_record_from_asset(uploaded_file.file.read(), warc_url, mime_type, warc)
          self.warc_size = warc_size[0]
          self.save(update_fields=['warc_size'])
          capture.save()
function_tokens: def write_uploaded_file ( self , uploaded_file , cache_break = False ) : from api . utils import get_mime_type , mime_type_lookup # local import to avoid circular import # normalize file name to upload.jpg, upload.png, upload.gif, or upload.pdf mime_type = get_mime_type ( uploaded_file . name ) file_name = f'upload.{mime_type_lookup[mime_type]["new_extension"]}' warc_url = f"file:///{self.guid}/{file_name}" # append a random number to warc_url if we're replacing a file, to avoid browser cache if cache_break : r = random . SystemRandom ( ) warc_url += f"?version={str(r.random()).replace('.', '')}" capture = Capture ( link = self , role = 'primary' , status = 'success' , record_type = 'resource' , user_upload = 'True' , content_type = mime_type , url = warc_url ) warc_size = [ ] # pass a mutable container to the context manager, so that it can populate it with the size of the finished warc with preserve_perma_warc ( self . guid , self . creation_timestamp , self . warc_storage_file ( ) , warc_size ) as warc : uploaded_file . file . seek ( 0 ) write_resource_record_from_asset ( uploaded_file . file . read ( ) , warc_url , mime_type , warc ) self . warc_size = warc_size [ 0 ] self . save ( update_fields = [ 'warc_size' ] ) capture . save ( )