Exemplo n.º 1
0
 def generate_download_url(self):
     bucket = getattr(settings, 'AWS_STORAGE_BUCKET_NAME')
     region = getattr(settings, 'S3DIRECT_REGION')
     access_key = getattr(settings, 'AWS_ACCESS_KEY_ID')
     secret_key = getattr(settings, 'AWS_SECRET_ACCESS_KEY')
     if not secret_key or not access_key or not bucket or not region:
         return "/product-not-found/"
     PROTECTED_DIR_NAME = getattr(settings, 'PROTECTED_DIR_NAME',
                                  'protected')
     path = "{base}/{file_path}".format(base=PROTECTED_DIR_NAME,
                                        file_path=str(self.file))
     aws_dl_object = AWSDownload(access_key, secret_key, bucket, region)
     file_url = aws_dl_object.generate_url(path,
                                           new_filename=self.display_name)
     return file_url
Exemplo n.º 2
0
	def generate_download_url(self):
		bucket = getattr(settings, "AWS_STORAGE_BUCKET_NAME")
		region = getattr(settings,"S3DIRECT_REGION")
		access_key = getattr(settings,"AWS_ACCESS_KEY_ID")
		secret_key = getattr(settings,"AWS_SECRET_ACCESS_KEY")
		if not secret_key or not access_key or not bucket or not region:
			print("Ca ne marche pas")
			return "/product-not-found/"
		PROTECTED_DIR_NAME = getattr(settings, "PROTECTED_DIR_NAME", "protected" )
		path ="{base}/{file_path}".format(base=PROTECTED_DIR_NAME, file_path=str(self.file))
		print(path)

		aws_dl_object =  AWSDownload(access_key=access_key, secret_key=secret_key, bucket=bucket, region=region)
		file_url = aws_dl_object.generate_url(path, self.display_name) #,new_filename='New awesome file')
		return file_url