@c8y/client 1018.228.0 → 1018.229.0
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/lib/bundles/client.umd.js +63 -0
- package/lib/bundles/client.umd.js.map +1 -1
- package/lib/bundles/client.umd.min.js +1 -1
- package/lib/bundles/client.umd.min.js.map +1 -1
- package/lib/cjs/src/inventory/InventoryBinaryService.js +63 -0
- package/lib/cjs/src/inventory/InventoryBinaryService.js.map +1 -1
- package/lib/esm2015/src/inventory/InventoryBinaryService.js +63 -0
- package/lib/esm2015/src/inventory/InventoryBinaryService.js.map +1 -1
- package/lib/src/inventory/InventoryBinaryService.d.ts +8 -0
- package/package.json +1 -1
|
@@ -5226,6 +5226,69 @@
|
|
|
5226
5226
|
return yield this.fetch(url, init);
|
|
5227
5227
|
});
|
|
5228
5228
|
}
|
|
5229
|
+
/**
|
|
5230
|
+
* Uploads a file and creates a managed object with its metadata. What's more, it invokes an upload progress callback.
|
|
5231
|
+
* @param file A file to be uploaded.
|
|
5232
|
+
* @param managedObject An object containing metadata about the file.
|
|
5233
|
+
* @param onProgress Event handler for progress update, invoked while the browser is uploading the file.
|
|
5234
|
+
*/
|
|
5235
|
+
createWithProgress(file, onProgress, managedObject = {}) {
|
|
5236
|
+
const url = `/${this.baseUrl}/${this.listUrl}`;
|
|
5237
|
+
const method = 'POST';
|
|
5238
|
+
const body = new browser();
|
|
5239
|
+
let fileName;
|
|
5240
|
+
let fileType;
|
|
5241
|
+
if (managedObject.fileName) {
|
|
5242
|
+
fileName = managedObject.fileName;
|
|
5243
|
+
delete managedObject.fileName;
|
|
5244
|
+
}
|
|
5245
|
+
if (managedObject.fileType) {
|
|
5246
|
+
fileType = managedObject.fileType;
|
|
5247
|
+
delete managedObject.fileType;
|
|
5248
|
+
}
|
|
5249
|
+
if (!fileName) {
|
|
5250
|
+
fileName = 'bin';
|
|
5251
|
+
}
|
|
5252
|
+
if (typeof File !== 'undefined' && file instanceof File) {
|
|
5253
|
+
fileName = file.name;
|
|
5254
|
+
fileType = file.type;
|
|
5255
|
+
}
|
|
5256
|
+
if (!managedObject.name) {
|
|
5257
|
+
managedObject.name = fileName;
|
|
5258
|
+
}
|
|
5259
|
+
if (!managedObject.type) {
|
|
5260
|
+
managedObject.type = fileType || 'c8y_upload';
|
|
5261
|
+
}
|
|
5262
|
+
body.append('file', file, fileName);
|
|
5263
|
+
body.append('object', JSON.stringify(managedObject));
|
|
5264
|
+
let bodyHeaders;
|
|
5265
|
+
if (typeof body.getHeaders === 'function') {
|
|
5266
|
+
bodyHeaders = body.getHeaders();
|
|
5267
|
+
}
|
|
5268
|
+
const headers = this.client.getFetchOptions().headers;
|
|
5269
|
+
Object.assign(headers, {
|
|
5270
|
+
accept: 'application/json'
|
|
5271
|
+
}, bodyHeaders);
|
|
5272
|
+
const xhr = new XMLHttpRequest();
|
|
5273
|
+
xhr.open(method, url, true);
|
|
5274
|
+
for (const key in headers) {
|
|
5275
|
+
if (headers.hasOwnProperty(key)) {
|
|
5276
|
+
xhr.setRequestHeader(key, headers[key]);
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
xhr.upload.addEventListener('progress', onProgress);
|
|
5280
|
+
xhr.send(body);
|
|
5281
|
+
return xhr;
|
|
5282
|
+
}
|
|
5283
|
+
getXMLHttpResponse(xhr) {
|
|
5284
|
+
return new Promise((res, rej) => {
|
|
5285
|
+
xhr.addEventListener('loadend', () => {
|
|
5286
|
+
xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 201)
|
|
5287
|
+
? res(JSON.parse(xhr.responseText))
|
|
5288
|
+
: rej(xhr.responseText ? { data: JSON.parse(xhr.responseText) } : 'Could not upload file.');
|
|
5289
|
+
});
|
|
5290
|
+
});
|
|
5291
|
+
}
|
|
5229
5292
|
/**
|
|
5230
5293
|
* Gets binary managed object's id from its download or self URL.
|
|
5231
5294
|
*
|