@uploadcare/upload-client 6.0.1-alpha.1 → 6.0.1-alpha.3
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 +11 -1
- package/dist/index.node.js +7 -1
- package/dist/index.react-native.js +12 -2
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -168,12 +168,14 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
168
168
|
* and https://bugs.chromium.org/p/chromium/issues/detail?id=1346628
|
|
169
169
|
*/
|
|
170
170
|
xhr.open(requestMethod, url, true);
|
|
171
|
+
console.log(`xhr.open(${requestMethod}, ${url}, true)`);
|
|
171
172
|
if (headers) {
|
|
172
173
|
Object.entries(headers).forEach((entry) => {
|
|
173
174
|
const [key, value] = entry;
|
|
174
175
|
typeof value !== 'undefined' &&
|
|
175
176
|
!Array.isArray(value) &&
|
|
176
177
|
xhr.setRequestHeader(key, value);
|
|
178
|
+
console.log(`xhr.setRequestHeader(${key}, ${value})`);
|
|
177
179
|
});
|
|
178
180
|
}
|
|
179
181
|
xhr.responseType = 'text';
|
|
@@ -225,6 +227,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
225
227
|
xhr.onerror = (progressEvent) => {
|
|
226
228
|
if (aborted)
|
|
227
229
|
return;
|
|
230
|
+
console.log('aboirt', xhr, progressEvent);
|
|
228
231
|
// only triggers if the request couldn't be made at all
|
|
229
232
|
reject(new UploadcareNetworkError(progressEvent));
|
|
230
233
|
};
|
|
@@ -242,6 +245,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
242
245
|
};
|
|
243
246
|
}
|
|
244
247
|
if (data) {
|
|
248
|
+
console.log(`xhr.send(${data})`);
|
|
245
249
|
xhr.send(data);
|
|
246
250
|
}
|
|
247
251
|
else {
|
|
@@ -257,6 +261,10 @@ const getFileOptions = ({ name }) => name ? [name] : [];
|
|
|
257
261
|
const transformFile = identity;
|
|
258
262
|
var getFormData = () => new FormData();
|
|
259
263
|
|
|
264
|
+
const isReactNativeUri = (uri) => {
|
|
265
|
+
return uri.startsWith('file:') || uri.startsWith('content:');
|
|
266
|
+
};
|
|
267
|
+
|
|
260
268
|
/**
|
|
261
269
|
* FileData type guard.
|
|
262
270
|
*/
|
|
@@ -265,7 +273,7 @@ const isFileData = (data) => {
|
|
|
265
273
|
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
266
274
|
(typeof File !== 'undefined' && data instanceof File) ||
|
|
267
275
|
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
268
|
-
(typeof data === 'string' && data
|
|
276
|
+
(typeof data === 'string' && isReactNativeUri(data))));
|
|
269
277
|
};
|
|
270
278
|
/**
|
|
271
279
|
* Uuid type guard.
|
|
@@ -324,9 +332,11 @@ function getFormDataParams(options) {
|
|
|
324
332
|
return params;
|
|
325
333
|
}
|
|
326
334
|
function buildFormData(options) {
|
|
335
|
+
console.log('buildFormData', options);
|
|
327
336
|
const formData = getFormData();
|
|
328
337
|
const paramsList = getFormDataParams(options);
|
|
329
338
|
for (const params of paramsList) {
|
|
339
|
+
console.log('params', params);
|
|
330
340
|
const [key, value, ...rest] = params;
|
|
331
341
|
// node form-data has another signature for append
|
|
332
342
|
formData.append(key, value, ...rest);
|
package/dist/index.node.js
CHANGED
|
@@ -285,6 +285,10 @@ const getFileOptions = ({ name, contentType }) => [
|
|
|
285
285
|
const transformFile = identity;
|
|
286
286
|
var getFormData = () => new NodeFormData();
|
|
287
287
|
|
|
288
|
+
const isReactNativeUri = (uri) => {
|
|
289
|
+
return uri.startsWith('file:') || uri.startsWith('content:');
|
|
290
|
+
};
|
|
291
|
+
|
|
288
292
|
/**
|
|
289
293
|
* FileData type guard.
|
|
290
294
|
*/
|
|
@@ -293,7 +297,7 @@ const isFileData = (data) => {
|
|
|
293
297
|
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
294
298
|
(typeof File !== 'undefined' && data instanceof File) ||
|
|
295
299
|
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
296
|
-
(typeof data === 'string' && data
|
|
300
|
+
(typeof data === 'string' && isReactNativeUri(data))));
|
|
297
301
|
};
|
|
298
302
|
/**
|
|
299
303
|
* Uuid type guard.
|
|
@@ -352,9 +356,11 @@ function getFormDataParams(options) {
|
|
|
352
356
|
return params;
|
|
353
357
|
}
|
|
354
358
|
function buildFormData(options) {
|
|
359
|
+
console.log('buildFormData', options);
|
|
355
360
|
const formData = getFormData();
|
|
356
361
|
const paramsList = getFormDataParams(options);
|
|
357
362
|
for (const params of paramsList) {
|
|
363
|
+
console.log('params', params);
|
|
358
364
|
const [key, value, ...rest] = params;
|
|
359
365
|
// node form-data has another signature for append
|
|
360
366
|
formData.append(key, value, ...rest);
|
|
@@ -168,12 +168,14 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
168
168
|
* and https://bugs.chromium.org/p/chromium/issues/detail?id=1346628
|
|
169
169
|
*/
|
|
170
170
|
xhr.open(requestMethod, url, true);
|
|
171
|
+
console.log(`xhr.open(${requestMethod}, ${url}, true)`);
|
|
171
172
|
if (headers) {
|
|
172
173
|
Object.entries(headers).forEach((entry) => {
|
|
173
174
|
const [key, value] = entry;
|
|
174
175
|
typeof value !== 'undefined' &&
|
|
175
176
|
!Array.isArray(value) &&
|
|
176
177
|
xhr.setRequestHeader(key, value);
|
|
178
|
+
console.log(`xhr.setRequestHeader(${key}, ${value})`);
|
|
177
179
|
});
|
|
178
180
|
}
|
|
179
181
|
xhr.responseType = 'text';
|
|
@@ -225,6 +227,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
225
227
|
xhr.onerror = (progressEvent) => {
|
|
226
228
|
if (aborted)
|
|
227
229
|
return;
|
|
230
|
+
console.log('aboirt', xhr, progressEvent);
|
|
228
231
|
// only triggers if the request couldn't be made at all
|
|
229
232
|
reject(new UploadcareNetworkError(progressEvent));
|
|
230
233
|
};
|
|
@@ -242,6 +245,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
242
245
|
};
|
|
243
246
|
}
|
|
244
247
|
if (data) {
|
|
248
|
+
console.log(`xhr.send(${data})`);
|
|
245
249
|
xhr.send(data);
|
|
246
250
|
}
|
|
247
251
|
else {
|
|
@@ -249,9 +253,13 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
249
253
|
}
|
|
250
254
|
});
|
|
251
255
|
|
|
256
|
+
const isReactNativeUri = (uri) => {
|
|
257
|
+
return uri.startsWith('file:') || uri.startsWith('content:');
|
|
258
|
+
};
|
|
259
|
+
|
|
252
260
|
const getFileOptions = ({ name }) => name ? [name] : [];
|
|
253
261
|
const transformFile = (file, name) => {
|
|
254
|
-
if (typeof file === 'string' &&
|
|
262
|
+
if (typeof file === 'string' && isReactNativeUri(file)) {
|
|
255
263
|
return { uri: file, name };
|
|
256
264
|
}
|
|
257
265
|
const uri = URL.createObjectURL(file);
|
|
@@ -268,7 +276,7 @@ const isFileData = (data) => {
|
|
|
268
276
|
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
269
277
|
(typeof File !== 'undefined' && data instanceof File) ||
|
|
270
278
|
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
271
|
-
(typeof data === 'string' && data
|
|
279
|
+
(typeof data === 'string' && isReactNativeUri(data))));
|
|
272
280
|
};
|
|
273
281
|
/**
|
|
274
282
|
* Uuid type guard.
|
|
@@ -327,9 +335,11 @@ function getFormDataParams(options) {
|
|
|
327
335
|
return params;
|
|
328
336
|
}
|
|
329
337
|
function buildFormData(options) {
|
|
338
|
+
console.log('buildFormData', options);
|
|
330
339
|
const formData = getFormData();
|
|
331
340
|
const paramsList = getFormDataParams(options);
|
|
332
341
|
for (const params of paramsList) {
|
|
342
|
+
console.log('params', params);
|
|
333
343
|
const [key, value, ...rest] = params;
|
|
334
344
|
// node form-data has another signature for append
|
|
335
345
|
formData.append(key, value, ...rest);
|