pyaws-s3 1.0.21__tar.gz → 1.0.23__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/PKG-INFO +1 -1
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3/s3.py +59 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3.egg-info/PKG-INFO +1 -1
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyproject.toml +1 -1
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/LICENSE.md +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/README.md +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3/__init__.py +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3.egg-info/SOURCES.txt +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3.egg-info/dependency_links.txt +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3.egg-info/requires.txt +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/pyaws_s3.egg-info/top_level.txt +0 -0
- {pyaws_s3-1.0.21 → pyaws_s3-1.0.23}/setup.cfg +0 -0
@@ -172,6 +172,65 @@ class S3Client:
|
|
172
172
|
logger.info(f"Pre-signed URL: {temp_url}")
|
173
173
|
|
174
174
|
return temp_url
|
175
|
+
|
176
|
+
def upload_bytes(self, *args, **kwargs: Any):
|
177
|
+
"""
|
178
|
+
Upload a Plotly Figure as a PNG image to an S3 bucket and generate a pre-signed URL.
|
179
|
+
|
180
|
+
Args:
|
181
|
+
fig (Figure): The Plotly Figure object to upload.
|
182
|
+
bucket_name (str): The name of the S3 bucket.
|
183
|
+
object_name (str): The name of the S3 object.
|
184
|
+
|
185
|
+
Keyword Args:
|
186
|
+
format_file (str): Format of the image. Defaults to 'png'.
|
187
|
+
|
188
|
+
Returns:
|
189
|
+
str: Pre-signed URL for the uploaded image.
|
190
|
+
|
191
|
+
Raises:
|
192
|
+
Exception: If there is an error uploading the image.
|
193
|
+
"""
|
194
|
+
try:
|
195
|
+
|
196
|
+
if args:
|
197
|
+
bytes_data = args[0] if len(args) > 0 else None
|
198
|
+
object_name = args[1] if len(args) > 1 else None
|
199
|
+
else:
|
200
|
+
bytes_data = kwargs.get("bytes_data", None)
|
201
|
+
object_name = kwargs.get("object_name", None)
|
202
|
+
|
203
|
+
if bytes_data is None:
|
204
|
+
raise Exception("Figure is None")
|
205
|
+
|
206
|
+
if object_name is None:
|
207
|
+
raise Exception("Object name is None")
|
208
|
+
|
209
|
+
format_file : FormatFile = kwargs.get("format_file", "pdf")
|
210
|
+
mimetypes = "application/pdf"
|
211
|
+
|
212
|
+
if format_file not in ["png", "jpeg", "svg", "html", "pdf"]:
|
213
|
+
raise Exception("Invalid format_file provided. Supported formats are: png, jpeg, svg, html, pdf")
|
214
|
+
if format_file == "png":
|
215
|
+
mimetypes = "image/png"
|
216
|
+
elif format_file == "jpeg":
|
217
|
+
mimetypes = "image/jpeg"
|
218
|
+
elif format_file == "svg":
|
219
|
+
mimetypes = "image/svg+xml"
|
220
|
+
elif format_file == "html":
|
221
|
+
mimetypes = "text/html"
|
222
|
+
elif format_file == "pdf":
|
223
|
+
mimetypes = "application/pdf"
|
224
|
+
else:
|
225
|
+
raise Exception("Invalid MIME type provided")
|
226
|
+
|
227
|
+
s3_resource = self._get_s3_resource()
|
228
|
+
|
229
|
+
s3_resource.Bucket(self.bucket_name).Object(object_name).put(Body=bytes_data, ContentType=mimetypes)
|
230
|
+
|
231
|
+
except Exception as e:
|
232
|
+
logger.error(f"Error uploading image: {str(e)}")
|
233
|
+
raise Exception(f"Error uploading image: {str(e)}")
|
175
234
|
|
176
235
|
def upload_image(self, *args, **kwargs: Any) -> str:
|
177
236
|
"""
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|