Skip to content

Instantly share code, notes, and snippets.

@gavinr

gavinr/index.js Secret

Created March 22, 2023 17:45
Show Gist options
  • Save gavinr/9a2dfd0e8084a9253706d34e8e2536a0 to your computer and use it in GitHub Desktop.
Save gavinr/9a2dfd0e8084a9253706d34e8e2536a0 to your computer and use it in GitHub Desktop.
import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
import {
createItem,
addItemPart,
commitItemUpload
} from "@esri/arcgis-rest-portal";
import { readFileSync } from "fs";
import { Blob } from "buffer";
const getIdentity = async () =>
await ArcGISIdentityManager.signIn({
username: "REPLACE_ME***********************************************************",
password: "REPLACE_ME***********************************************************"
});
const auth = await getIdentity();
const file = readFileSync('./test.geojson');
const fileBlob = new Blob([new Uint8Array(file).buffer], {
type: 'application/geo+json',
});
const item = await createItem({
item: {
title: 'Hello World',
type: 'GeoJson',
},
authentication: auth,
multipart: true,
filename: 'test.geojson',
async: true,
overwrite: true,
});
console.log('item.id', item.id);
// // Note: You can add params: { f: 'text' } to see the HTML response
const part = await addItemPart({
id: item.id,
file: fileBlob,
partNum: 1,
authentication: auth,
});
// const commit = await commitItemUpload({
// item: { title: 'Hello World', type: 'GeoJson' },
// id: part.id,
// authentication: auth,
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment