-
-
Save gavinr/9a2dfd0e8084a9253706d34e8e2536a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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