@uploadcare/upload-client 6.0.1-alpha.5 → 6.0.1-alpha.7
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/index.browser.js +9 -2
- package/dist/index.node.js +9 -2
- package/dist/index.react-native.js +16 -6
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -264,6 +264,13 @@ var getFormData = () => new FormData();
|
|
|
264
264
|
const isReactNativeUri = (uri) => {
|
|
265
265
|
return uri.startsWith('file:') || uri.startsWith('content:');
|
|
266
266
|
};
|
|
267
|
+
const isReactNativeAsset = (asset) => {
|
|
268
|
+
return (typeof asset === 'object' &&
|
|
269
|
+
!!asset &&
|
|
270
|
+
'uri' in asset &&
|
|
271
|
+
typeof asset.uri === 'string' &&
|
|
272
|
+
isReactNativeUri(asset.uri));
|
|
273
|
+
};
|
|
267
274
|
|
|
268
275
|
/**
|
|
269
276
|
* FileData type guard.
|
|
@@ -273,7 +280,8 @@ const isFileData = (data) => {
|
|
|
273
280
|
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
274
281
|
(typeof File !== 'undefined' && data instanceof File) ||
|
|
275
282
|
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
276
|
-
(typeof data === 'string' && isReactNativeUri(data))
|
|
283
|
+
(typeof data === 'string' && isReactNativeUri(data)) ||
|
|
284
|
+
(typeof data === 'object' && isReactNativeAsset(data))));
|
|
277
285
|
};
|
|
278
286
|
/**
|
|
279
287
|
* Uuid type guard.
|
|
@@ -466,7 +474,6 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
466
474
|
}),
|
|
467
475
|
headers: {
|
|
468
476
|
'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
|
|
469
|
-
'content-type': 'multipart/form-data'
|
|
470
477
|
},
|
|
471
478
|
data: buildFormData({
|
|
472
479
|
file: {
|
package/dist/index.node.js
CHANGED
|
@@ -288,6 +288,13 @@ var getFormData = () => new NodeFormData();
|
|
|
288
288
|
const isReactNativeUri = (uri) => {
|
|
289
289
|
return uri.startsWith('file:') || uri.startsWith('content:');
|
|
290
290
|
};
|
|
291
|
+
const isReactNativeAsset = (asset) => {
|
|
292
|
+
return (typeof asset === 'object' &&
|
|
293
|
+
!!asset &&
|
|
294
|
+
'uri' in asset &&
|
|
295
|
+
typeof asset.uri === 'string' &&
|
|
296
|
+
isReactNativeUri(asset.uri));
|
|
297
|
+
};
|
|
291
298
|
|
|
292
299
|
/**
|
|
293
300
|
* FileData type guard.
|
|
@@ -297,7 +304,8 @@ const isFileData = (data) => {
|
|
|
297
304
|
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
298
305
|
(typeof File !== 'undefined' && data instanceof File) ||
|
|
299
306
|
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
300
|
-
(typeof data === 'string' && isReactNativeUri(data))
|
|
307
|
+
(typeof data === 'string' && isReactNativeUri(data)) ||
|
|
308
|
+
(typeof data === 'object' && isReactNativeAsset(data))));
|
|
301
309
|
};
|
|
302
310
|
/**
|
|
303
311
|
* Uuid type guard.
|
|
@@ -490,7 +498,6 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
490
498
|
}),
|
|
491
499
|
headers: {
|
|
492
500
|
'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
|
|
493
|
-
'content-type': 'multipart/form-data'
|
|
494
501
|
},
|
|
495
502
|
data: buildFormData({
|
|
496
503
|
file: {
|
|
@@ -256,15 +256,25 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
256
256
|
const isReactNativeUri = (uri) => {
|
|
257
257
|
return uri.startsWith('file:') || uri.startsWith('content:');
|
|
258
258
|
};
|
|
259
|
+
const isReactNativeAsset = (asset) => {
|
|
260
|
+
return (typeof asset === 'object' &&
|
|
261
|
+
!!asset &&
|
|
262
|
+
'uri' in asset &&
|
|
263
|
+
typeof asset.uri === 'string' &&
|
|
264
|
+
isReactNativeUri(asset.uri));
|
|
265
|
+
};
|
|
259
266
|
|
|
260
267
|
const getFileOptions = ({ name }) => name ? [name] : [];
|
|
261
268
|
const transformFile = (file, name, contentType) => {
|
|
262
269
|
if (typeof file === 'string' && isReactNativeUri(file)) {
|
|
270
|
+
return { uri: file, name, type: contentType };
|
|
271
|
+
}
|
|
272
|
+
if (isReactNativeAsset(file)) {
|
|
263
273
|
return file;
|
|
264
274
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return
|
|
275
|
+
const uri = URL.createObjectURL(file);
|
|
276
|
+
const type = contentType || file.type;
|
|
277
|
+
return { uri, name, type };
|
|
268
278
|
};
|
|
269
279
|
var getFormData = () => new FormData();
|
|
270
280
|
|
|
@@ -276,7 +286,8 @@ const isFileData = (data) => {
|
|
|
276
286
|
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
277
287
|
(typeof File !== 'undefined' && data instanceof File) ||
|
|
278
288
|
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
279
|
-
(typeof data === 'string' && isReactNativeUri(data))
|
|
289
|
+
(typeof data === 'string' && isReactNativeUri(data)) ||
|
|
290
|
+
(typeof data === 'object' && isReactNativeAsset(data))));
|
|
280
291
|
};
|
|
281
292
|
/**
|
|
282
293
|
* Uuid type guard.
|
|
@@ -312,7 +323,7 @@ const isFileValue = (value) => !!value &&
|
|
|
312
323
|
function collectParams(params, inputKey, inputValue) {
|
|
313
324
|
if (isFileValue(inputValue)) {
|
|
314
325
|
const { name, contentType } = inputValue;
|
|
315
|
-
const file = transformFile(inputValue.data); // lgtm [js/superfluous-trailing-arguments]
|
|
326
|
+
const file = transformFile(inputValue.data, name, contentType); // lgtm [js/superfluous-trailing-arguments]
|
|
316
327
|
const options = getFileOptions({ name, contentType });
|
|
317
328
|
params.push([inputKey, file, ...options]);
|
|
318
329
|
}
|
|
@@ -469,7 +480,6 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
469
480
|
}),
|
|
470
481
|
headers: {
|
|
471
482
|
'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
|
|
472
|
-
'content-type': 'multipart/form-data'
|
|
473
483
|
},
|
|
474
484
|
data: buildFormData({
|
|
475
485
|
file: {
|