def upload_file(self, file_name, file_path): """ Upload a given file from the file_path to the bucket with the new name/path file_name. """ upload_key = Key(bucket=self.bucket, name=file_name) content_type = "text/plain" if file_name.endswith(".html"): content_type = "text/html" elif file_name.endswith(".jpg"): content_type = "image/jpeg" elif file_name.endswith(".png"): content_type = "image/png" upload_key.set_contents_from_filename(file_path, headers={"Content-Type": content_type}) upload_key.url = upload_key.generate_url(expires_in=3600).split("?")[0] try: upload_key.make_public() except Exception: pass
def upload_file(self, file_name, file_path): """upload a given file from the file_path to the bucket with the new name/path file_name""" upload_key = Key(bucket=self.bucket, name=file_name) content_type = "text/plain" if file_name.endswith(".html"): content_type = "text/html" if file_name.endswith(".jpg"): content_type = "image/jpg" upload_key.set_contents_from_filename(file_path, headers={"Content-Type":content_type}) upload_key.url = \ upload_key.generate_url(expires_in=3600).split("?")[0] try: upload_key.make_public() except: pass # we get a http version error here, we're going to pass return file_name
def upload_file(self, file_name, file_path): """ Upload a given file from the file_path to the bucket with the new name/path file_name. """ upload_key = Key(bucket=self.bucket, name=file_name) content_type = "text/plain" if file_name.endswith(".html"): content_type = "text/html" elif file_name.endswith(".jpg"): content_type = "image/jpeg" elif file_name.endswith(".png"): content_type = "image/png" upload_key.set_contents_from_filename( file_path, headers={"Content-Type": content_type}) upload_key.url = \ upload_key.generate_url(expires_in=3600).split("?")[0] try: upload_key.make_public() except Exception: pass