in examples/demo-app/src/cloud-providers/carto/carto-provider.js [94:160]
async uploadMap({mapData = {}, options = {}}) {
try {
const {isPublic = true, overwrite = true} = options;
const {map: {config, datasets, info} = {}, thumbnail} = mapData;
const cartoDatasets = datasets.map(this._convertDataset);
const cs = await this._carto.getCustomStorage();
const {title, description} = info;
const name = title;
const thumbnailBase64 =
mapData && thumbnail ? await this._blobToBase64(mapData.thumbnail) : null;
let result;
if (overwrite) {
result = await cs.updateVisualization(
{
id: this.currentMap.id,
name,
description,
thumbnail: thumbnailBase64,
config: JSON.stringify(config),
isprivate: this.currentMap.isprivate
},
cartoDatasets
);
} else {
// TODO: Ask for changing current shared map generation because of being too oriented to file based clouds
// Check public name generation and replace
const regex = /(?:^keplergl_)([a-z0-9]+)(?:.json$)/;
const capturedName = name.match(regex);
const visName = capturedName ? `sharedmap_${capturedName[1]}` : name;
result = await cs.createVisualization(
{
name: visName,
description,
thumbnail: thumbnailBase64,
config: JSON.stringify(config),
isprivate: !isPublic
},
cartoDatasets,
true
);
}
if (result) {
this.currentMap = result;
}
return {
shareUrl: this._getMapPermalinkFromParams(
{
mapId: result.id,
owner: this._carto.username,
privateMap: !isPublic
},
true
),
folderLink: this._folderLink.replace('{user}', this._carto.username)
};
} catch (error) {
this._manageErrors(error);
}
}