-
Notifications
You must be signed in to change notification settings - Fork 118
/
getAttachments.ts
55 lines (50 loc) · 1.74 KB
/
getAttachments.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import { request, cleanUrl } from "@esri/arcgis-rest-request";
import { IGetLayerOptions } from "./helpers";
/**
* Request options to fetch `attachmentInfos` of a feature by id. See [Attachment Infos](https://developers.arcgis.com/rest/services-reference/attachment-infos-feature-service-.htm) for more information.
*
*/
export interface IGetAttachmentsOptions extends IGetLayerOptions {
/**
* Unique identifier of feature to request related `attachmentInfos`.
*/
featureId: number;
}
/**
* Attachment, a.k.a. `attachmentInfo`. See [Attachment](https://developers.arcgis.com/rest/services-reference/attachment-feature-service-.htm) for more information.
*/
export interface IAttachmentInfo {
id: number;
contentType: string;
size: number;
name: string;
}
/**
* ```js
* import { getAttachments } from '@esri/arcgis-rest-feature-layer';
* //
* getAttachments({
* url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0",
* featureId: 8484
* });
* ```
* Request `attachmentInfos` of a feature by id. See [Attachment Infos](https://developers.arcgis.com/rest/services-reference/attachment-infos-feature-service-.htm) for more information.
*
* @param requestOptions - Options for the request.
* @returns A Promise that will resolve with the `getAttachments()` response.
*/
export function getAttachments(
requestOptions: IGetAttachmentsOptions
): Promise<{ attachmentInfos: IAttachmentInfo[] }> {
const options: IGetAttachmentsOptions = {
httpMethod: "GET",
...requestOptions
};
// pass through
return request(
`${cleanUrl(options.url)}/${options.featureId}/attachments`,
options
);
}