polgo-upload-kit 1.1.7 → 1.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polgo-upload-kit",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "main": "src/polgoUploadClient.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@ class PolgoUploadClient {
9
9
  this.token = token;
10
10
  }
11
11
 
12
- async uploadFile(bufferArquivo, bucket, options = {}) {
12
+ async uploadFile(bufferArquivo, bucket, options = {}, onProgress) {
13
13
  const mimeType = bufferArquivo.type;
14
14
 
15
15
  const fileBlob = new Blob([bufferArquivo], { type: mimeType });
@@ -33,12 +33,21 @@ class PolgoUploadClient {
33
33
  headers: {
34
34
  Authorization: `Bearer ${this.token}`,
35
35
  },
36
+ onUploadProgress: (progressEvent) => {
37
+ const percentCompleted = Math.round(
38
+ (progressEvent.loaded * 100) / progressEvent.total
39
+ );
40
+ if (typeof onProgress === "function") {
41
+ onProgress(percentCompleted);
42
+ }
43
+ },
36
44
  });
45
+
37
46
  return response.data;
38
47
  } catch (error) {
39
48
  console.error("Erro ao fazer upload do arquivo:", error.message);
40
49
  throw new Error(
41
- 'Falha ao realizar o upload do arquivo: ${error.message}'
50
+ `Falha ao realizar o upload do arquivo: ${error.message}`
42
51
  );
43
52
  }
44
53
  }