datasync-blob 1.1.15 → 1.1.18
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.
- package/dist/components/DsBlob.js +31 -3
- package/package.json +1 -1
|
@@ -93,7 +93,7 @@ class DsBlob extends _react.Component {
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
//-----------------------------------------------------------------------------------------------------------------------------------------
|
|
96
|
-
|
|
96
|
+
storeBase64ImageToImg = e => {
|
|
97
97
|
var image = document.createElement('img');
|
|
98
98
|
image.onload = this.reduceImage;
|
|
99
99
|
console.log("storeImageToImg:e.currentTarget.result = ", e.currentTarget.result);
|
|
@@ -101,12 +101,36 @@ class DsBlob extends _react.Component {
|
|
|
101
101
|
image.src = e.currentTarget.result;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
//-----------------------------------------------------------------------------------------------------------------------------------------
|
|
105
|
+
storeBinaryImageToImg = e => {
|
|
106
|
+
var image = document.createElement('img');
|
|
107
|
+
image.onload = this.reduceImage;
|
|
108
|
+
console.log("storeBinaryImageToImg:e.currentTarget.result = ", e.currentTarget.result);
|
|
109
|
+
alert("storeBinaryImageToImg !");
|
|
110
|
+
// Convert ArrayBuffer to Blob URL since image.src cannot accept ArrayBuffer directly
|
|
111
|
+
// Use the detected image type from the original file
|
|
112
|
+
const imageType = this.currentImageType || 'image/jpeg'; // fallback to jpeg
|
|
113
|
+
const blob = new Blob([e.currentTarget.result], {
|
|
114
|
+
type: imageType
|
|
115
|
+
});
|
|
116
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
117
|
+
image.src = blobUrl;
|
|
118
|
+
|
|
119
|
+
// Clean up blob URL after image loads to prevent memory leaks
|
|
120
|
+
image.onload = loadEvent => {
|
|
121
|
+
this.reduceImage(loadEvent);
|
|
122
|
+
URL.revokeObjectURL(blobUrl);
|
|
123
|
+
// Clear the stored image type
|
|
124
|
+
this.currentImageType = null;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
104
128
|
//-----------------------------------------------------------------------------------------------------------------------------------------
|
|
105
129
|
readImageAsBase64 = async aPictureFile => {
|
|
106
130
|
let _reader = new FileReader();
|
|
107
131
|
console.log("readImageAsBase64:aPictureFile = ", aPictureFile);
|
|
108
132
|
alert("readImageAsBase64 !");
|
|
109
|
-
_reader.onload = this.
|
|
133
|
+
_reader.onload = this.storeBase64ImageToImg;
|
|
110
134
|
_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.
|
|
111
135
|
};
|
|
112
136
|
|
|
@@ -115,7 +139,11 @@ class DsBlob extends _react.Component {
|
|
|
115
139
|
let _reader = new FileReader();
|
|
116
140
|
console.log("readImageAsBinary:aPictureFile = ", aPictureFile);
|
|
117
141
|
alert("readImageAsBinary !");
|
|
118
|
-
|
|
142
|
+
|
|
143
|
+
// Store the image type for use in storeBinaryImageToImg
|
|
144
|
+
this.currentImageType = aPictureFile.type;
|
|
145
|
+
console.log("Detected image type:", this.currentImageType);
|
|
146
|
+
_reader.onload = this.storeBinaryImageToImg;
|
|
119
147
|
_reader.readAsArrayBuffer(aPictureFile); //The readAsArrayBuffer() method reads the file as genuine binary content without base64 conversion.
|
|
120
148
|
};
|
|
121
149
|
|