datasync-blob 1.1.25 → 1.1.26

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.
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.DsBlob = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _reactToastify = require("react-toastify");
10
- require("react-toastify/dist/ReactToastify.css");
11
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
10
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
11
  class DsBlob extends _react.Component {
@@ -111,9 +109,6 @@ class DsBlob extends _react.Component {
111
109
  throw error;
112
110
  }
113
111
  };
114
- setPicture = data => {
115
- console.log("setPicture => Fake procedure canbe deleted !");
116
- };
117
112
 
118
113
  //-----------------------------------------
119
114
  convert_blob_picture_into_cloud_file = async pictureBlob => {
@@ -131,10 +126,7 @@ class DsBlob extends _react.Component {
131
126
  if (pictureBlob.data && pictureBlob.data.startsWith('blob:')) {
132
127
  URL.revokeObjectURL(pictureBlob.data);
133
128
  }
134
- this.setPicture(pictureBlob.cloud_url_prefix); //Display the image using the cloud URL only if upload succeeded
135
- _reactToastify.toast.success("Image uploadée");
136
- console.log("pictureBlob->", pictureBlob);
137
-
129
+ this.setData(pictureBlob.cloud_url_prefix);
138
130
  //inform parent component of the new cloud URL for the uploaded image
139
131
  this.props.uploadPicture({
140
132
  data: pictureBlob.cloud_url_prefix
@@ -145,7 +137,6 @@ class DsBlob extends _react.Component {
145
137
  }
146
138
  }
147
139
  } catch (error) {
148
- _reactToastify.toast.error("Erreur lors du téléchargement de l'image");
149
140
  console.error("Upload error:", error);
150
141
  }
151
142
  };
@@ -200,162 +191,67 @@ class DsBlob extends _react.Component {
200
191
  }
201
192
  }
202
193
 
194
+ //Compute jpeg compression ratio
195
+ let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
196
+
203
197
  //Build 2d picture
204
198
  canvas.width = width;
205
199
  canvas.height = height;
206
200
  context = canvas.getContext('2d');
207
201
  context.drawImage(imageSource, 0, 0, width, height);
202
+ if (this.props.cloud_storage) {
203
+ canvas.toBlob(async blob => {
204
+ if (blob) {
205
+ console.log("Binary blob created, size:", blob.size);
206
+ if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " blob.size = ", blob.size);
207
+
208
+ // Fallback: use blob URL for display but keep binary data
209
+ const blobUrl = URL.createObjectURL(blob);
210
+
211
+ // Convert blob to ArrayBuffer to maintain genuine binary data
212
+ const reader = new FileReader();
213
+ reader.onload = () => {
214
+ const binaryData = reader.result; // ArrayBuffer - genuine binary data
215
+ console.log("Fallback: Using binary data, size:", binaryData.byteLength);
216
+
217
+ //Call the upload callback with both blob URL for display and binary data for upload
218
+ this.convert_blob_picture_into_cloud_file({
219
+ data: blobUrl,
220
+ // For display in img tag
221
+ binaryData: binaryData,
222
+ // Genuine JPEG binary stream
223
+ cloud_url_prefix: this.props.cloud_url_prefix,
224
+ // Pass cloud URL prefix if needed for parent component
225
+ isBlobUrl: true // Flag to track blob URLs for cleanup
226
+ });
227
+ };
228
+ reader.readAsArrayBuffer(blob);
229
+ } else {
230
+ console.error("Failed to create blob from canvas");
231
+ }
232
+ }, 'image/jpeg', jpegCompressionRatio);
233
+ } else {
234
+ //Jpeg conversion
208
235
 
209
- //Jpeg conversion
210
- let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
211
- let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
236
+ let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
237
+
238
+ if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
239
+ const processedData = canvasData ? canvasData : "";
240
+ this.setData(processedData);
212
241
 
213
- if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
214
- const processedData = this.props.removebase64 ? canvasData ? canvasData.substring("data:image/png;base64".length) : "" : canvasData ? canvasData : "";
215
- this.setData(processedData);
216
- if (this.props.removebase64) {
217
- //remove base64 prefix if property is set
218
- this.props.uploadPicture({
219
- data: processedData
220
- });
221
- } else {
222
242
  //Keep base 64 prefix as it is
223
243
  this.props.uploadPicture({
224
244
  data: processedData
225
245
  });
226
246
  }
227
247
  };
228
- //-----------------------------------------------------------------------------------------------------------------------------------------
229
- reduceBinaryImage = e => {
230
- let imageSource = e.path && e.path[0] || e.srcElement; //Safari compliancy
231
-
232
- if (this.debugging) console.log("imageSource = ", imageSource);
233
- var canvas = document.createElement('canvas'),
234
- context,
235
- width = imageSource.width,
236
- height = imageSource.height;
237
-
238
- //Exact size props are set
239
- if (this.props.width && this.props.height) {
240
- //Check image size
241
- if (width > this.props.width || height > this.props.height) {
242
- alert("L'image est trop grande, le format requis est " + this.props.width + "x" + this.props.height);
243
- return;
244
- }
245
-
246
- //Check image size
247
- if (width < this.props.width || height < this.props.height) {
248
- alert("L'image est trop petite, le format requis est " + this.props.width + "x" + this.props.height);
249
- return;
250
- }
251
- }
252
-
253
- //Max size props are set
254
- if (this.props.maxWidth && this.props.maxHeight) {
255
- if (width > height) {
256
- //Check resize is enabled
257
- if (!this.props.reduceImage) {
258
- alert("L'image est trop large ! la largeur maximale est de " + this.props.maxWidth);
259
- return;
260
- }
261
- if (width > this.props.maxWidth) {
262
- height *= this.props.maxWidth / width;
263
- width = this.props.maxWidth;
264
- }
265
- } else {
266
- if (height > this.props.maxHeight) {
267
- //Check resize is enabled
268
- if (!this.props.reduceImage) {
269
- alert("L'image est trop haute, la hauteur maximale est de " + this.props.maxHeight);
270
- return;
271
- }
272
- width *= this.props.maxHeight / height;
273
- height = this.props.maxHeight;
274
- }
275
- }
276
- }
277
-
278
- //Build 2d picture
279
- canvas.width = width;
280
- canvas.height = height;
281
- context = canvas.getContext('2d');
282
- context.drawImage(imageSource, 0, 0, width, height);
283
-
284
- //Binary conversion using toBlob to maintain binary output
285
- let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
286
- canvas.toBlob(async blob => {
287
- if (blob) {
288
- console.log("Binary blob created, size:", blob.size);
289
- if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " blob.size = ", blob.size);
290
-
291
- // Fallback: use blob URL for display but keep binary data
292
- const blobUrl = URL.createObjectURL(blob);
293
-
294
- // Convert blob to ArrayBuffer to maintain genuine binary data
295
- const reader = new FileReader();
296
- reader.onload = () => {
297
- const binaryData = reader.result; // ArrayBuffer - genuine binary data
298
- console.log("Fallback: Using binary data, size:", binaryData.byteLength);
299
-
300
- // Store both display URL and binary data
301
- this.setData(blobUrl, binaryData);
302
- this.props.uploadPicture({
303
- data: this.props.cloud_url_prefix,
304
- // Pass the cloud URL for display
305
- binaryData: null,
306
- // Clear binary data since we now have a cloud URL
307
- cloud_url_prefix: this.props.cloud_url_prefix,
308
- // Pass cloud URL prefix if needed for parent component
309
- isBlobUrl: false // The final URL is not a blob URL, it's a cloud URL
310
- });
311
-
312
- //Call the upload callback with both blob URL for display and binary data for upload
313
- this.convert_blob_picture_into_cloud_file({
314
- data: blobUrl,
315
- // For display in img tag
316
- binaryData: binaryData,
317
- // Genuine JPEG binary stream
318
- cloud_url_prefix: this.props.cloud_url_prefix,
319
- // Pass cloud URL prefix if needed for parent component
320
- isBlobUrl: true // Flag to track blob URLs for cleanup
321
- });
322
- };
323
- reader.readAsArrayBuffer(blob);
324
- } else {
325
- console.error("Failed to create blob from canvas");
326
- }
327
- }, 'image/jpeg', jpegCompressionRatio);
328
- };
329
248
 
330
249
  //-----------------------------------------------------------------------------------------------------------------------------------------
331
250
  storeBase64ImageToImg = e => {
332
- var image = document.createElement('img');
333
- image.onload = this.reduceBase64Image;
251
+ var DOM_image = document.createElement('img');
252
+ DOM_image.onload = this.reduceBase64Image;
334
253
  console.log("storeBase64ImageToImg:e.currentTarget.result = ", e.currentTarget.result);
335
- image.src = e.currentTarget.result;
336
- };
337
-
338
- //-----------------------------------------------------------------------------------------------------------------------------------------
339
- storeBinaryImageToImg = e => {
340
- var image = document.createElement('img');
341
- //2Do DEBUG image.onload = this.reduceImage;
342
- console.log("storeBinaryImageToImg:e.currentTarget.result = ", e.currentTarget.result);
343
- // Convert ArrayBuffer to Blob URL since image.src cannot accept ArrayBuffer directly
344
- // Use the detected image type from the original file
345
- const imageType = this.currentImageType || 'image/jpeg'; // fallback to jpeg
346
- const blob = new Blob([e.currentTarget.result], {
347
- type: imageType
348
- });
349
- const blobUrl = URL.createObjectURL(blob);
350
- image.src = blobUrl;
351
-
352
- // Clean up blob URL after image loads to prevent memory leaks
353
- image.onload = loadEvent => {
354
- this.reduceBinaryImage(loadEvent);
355
- URL.revokeObjectURL(blobUrl);
356
- // Clear the stored image type
357
- this.currentImageType = null;
358
- };
254
+ DOM_image.src = e.currentTarget.result;
359
255
  };
360
256
 
361
257
  //-----------------------------------------------------------------------------------------------------------------------------------------
@@ -366,18 +262,6 @@ class DsBlob extends _react.Component {
366
262
  _reader.readAsDataURL(aPictureFile); //The readAsDataURL() method of the FileReader interface is used to read the contents of the specified file's data as a base64 encoded string.
367
263
  };
368
264
 
369
- //-----------------------------------------------------------------------------------------------------------------------------------------
370
- readImageAsBinary = async aPictureFile => {
371
- let _reader = new FileReader();
372
- console.log("readImageAsBinary:aPictureFile = ", aPictureFile);
373
-
374
- // Store the image type for use in storeBinaryImageToImg
375
- this.currentImageType = aPictureFile.type;
376
- console.log("Detected image type:", this.currentImageType);
377
- _reader.onload = this.storeBinaryImageToImg;
378
- _reader.readAsArrayBuffer(aPictureFile); //The readAsArrayBuffer() method reads the file as genuine binary content without base64 conversion.
379
- };
380
-
381
265
  //-----------------------------------------------------------------------------------------------------------------------------------------
382
266
  resetUpload = () => {
383
267
  // Clean up any blob URLs before resetting
@@ -453,11 +337,7 @@ class DsBlob extends _react.Component {
453
337
  if (errCount == errs.length) {
454
338
  //None new error occurs
455
339
  if (this.debugging) console.log("readImageAsBase64::", file.name);
456
- if (this.props.cloud_storage) {
457
- this.readImageAsBinary(file);
458
- } else {
459
- this.readImageAsBase64(file);
460
- }
340
+ this.readImageAsBase64(file);
461
341
  }
462
342
  });
463
343
  if (errs.length) {
@@ -480,8 +360,7 @@ class DsBlob extends _react.Component {
480
360
  }
481
361
 
482
362
  // Otherwise, treat as base64 and add appropriate prefix
483
- const prefix = this.props.removebase64 ? "data:image/png;base64," : "";
484
- return prefix + this.state.data;
363
+ return this.state.data;
485
364
  };
486
365
 
487
366
  //-----------------------------------------------------------------------------------------------------------------------------------------
@@ -580,17 +459,7 @@ class DsBlob extends _react.Component {
580
459
  type: "button",
581
460
  value: "Effacer",
582
461
  onClick: this.resetUpload
583
- })), /*#__PURE__*/_react.default.createElement(_reactToastify.ToastContainer, {
584
- position: "top-right",
585
- autoClose: 3000,
586
- hideProgressBar: false,
587
- newestOnTop: false,
588
- closeOnClick: true,
589
- rtl: false,
590
- pauseOnFocusLoss: true,
591
- draggable: true,
592
- pauseOnHover: true
593
- }));
462
+ })));
594
463
  }
595
464
  }
596
465
  exports.DsBlob = DsBlob;
@@ -608,7 +477,6 @@ DsBlob.propTypes = {
608
477
  // Image processing options
609
478
  reduceImage: _propTypes.default.bool,
610
479
  jpegQuality: _propTypes.default.number,
611
- removebase64: _propTypes.default.bool,
612
480
  // Cloud storage options
613
481
  cloud_storage: _propTypes.default.bool,
614
482
  cloud_url_prefix: _propTypes.default.string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datasync-blob",
3
- "version": "1.1.25",
3
+ "version": "1.1.26",
4
4
  "description": "Datasync Blob component",
5
5
  "main": "./dist/components/DsBlob.js",
6
6
  "files": [
@@ -42,8 +42,5 @@
42
42
  },
43
43
  "keywords": [],
44
44
  "author": "",
45
- "license": "ISC",
46
- "dependencies": {
47
- "react-toastify": "^11.1.0"
48
- }
45
+ "license": "ISC"
49
46
  }