@servicemind.tis/tis-image-and-file-upload-and-view 1.0.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/README.md +305 -0
- package/fesm2022/servicemind.tis-tis-image-and-file-upload-and-view.mjs +1029 -0
- package/fesm2022/servicemind.tis-tis-image-and-file-upload-and-view.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/interfaces/file-viewer-file-type.type.d.ts +20 -0
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/services/file-upload.service.d.ts +13 -0
- package/lib/services/image-upload.service.d.ts +13 -0
- package/lib/services/tis-helper.service.d.ts +25 -0
- package/lib/tis-confirmation-dialog/tis-confirmation-dialog.component.d.ts +10 -0
- package/lib/tis-error-dialog/tis-error-dialog.component.d.ts +10 -0
- package/lib/tis-file-viewer/tis-file-viewer.component.d.ts +5 -0
- package/lib/tis-image-and-file-upload-and-view/tis-image-and-file-upload-and-view.component.d.ts +84 -0
- package/lib/tis-image-and-file-upload-and-view.module.d.ts +18 -0
- package/lib/tis-image-and-file-upload-and-view.service.d.ts +6 -0
- package/lib/tis-preview-image/tis-preview-image.component.d.ts +19 -0
- package/package.json +28 -0
- package/public-api.d.ts +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# tis-image-and-file-upload-and-view
|
|
2
|
+
|
|
3
|
+
An all-in-one **image and file upload/view** Angular component by **Thai Informatic Systems Co. Ltd.**, designed for modern enterprise applications. This library provides a highly customizable drag-and-drop or button-triggered upload UI, with seamless preview and viewer integration for files including images, PDFs, videos, Excel, and more.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@servicemind.tis/tis-image-and-file-upload-and-view)
|
|
6
|
+
[](https://www.npmjs.com/package/@servicemind.tis/tis-image-and-file-upload-and-view)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## π Features
|
|
12
|
+
|
|
13
|
+
- β
Image and file upload with S3-style pre-signed URL handling
|
|
14
|
+
- β
Support for images, PDFs, Excel, CSV, videos, and raw files
|
|
15
|
+
- β
Built-in preview & viewer components
|
|
16
|
+
- β
Optional confirmation dialogs
|
|
17
|
+
- β
Fully customizable UI and dialog labels
|
|
18
|
+
- β
Support for standalone and module-based Angular apps
|
|
19
|
+
- β
Supports multiple uploads, size control, and compression toggle
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## π¦ Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @servicemind.tis/tis-image-and-file-upload-and-view
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Peer Dependencies
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @angular/material @angular/cdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## π§© Module Setup
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { TisImageAndFileUploadAndViewModule } from '@servicemind.tis/tis-image-and-file-upload-and-view';
|
|
41
|
+
|
|
42
|
+
@NgModule({
|
|
43
|
+
imports: [TisImageAndFileUploadAndViewModule]
|
|
44
|
+
})
|
|
45
|
+
export class MyFeatureModule {}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## βοΈ Configuration Interfaces
|
|
51
|
+
|
|
52
|
+
### `UrlConfig`
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
export interface UrlConfig {
|
|
56
|
+
getUploadUrl: string;
|
|
57
|
+
attachToEntity: string;
|
|
58
|
+
removeImage: string;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `DialogConfig`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
export interface DialogConfig {
|
|
66
|
+
title: string;
|
|
67
|
+
message: string | null;
|
|
68
|
+
iconClass: string;
|
|
69
|
+
icon: string;
|
|
70
|
+
approveButtonText: string | null;
|
|
71
|
+
approveButtonClass: string;
|
|
72
|
+
cancelButtonText: string | null;
|
|
73
|
+
cancelButtonClass: string;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## π§ Component: `<tis-image-and-file-upload-and-view>`
|
|
80
|
+
|
|
81
|
+
This is the main component that allows users to upload and preview files.
|
|
82
|
+
|
|
83
|
+
### β
Inputs
|
|
84
|
+
|
|
85
|
+
| Input | Type | Description |
|
|
86
|
+
|---------------|---------------------|-------------|
|
|
87
|
+
| `urlConfig` | `UrlConfig` | API endpoints for upload, attach, delete |
|
|
88
|
+
| `entityType` | `string` | Type of the associated entity |
|
|
89
|
+
| `disabled` | `boolean` | Disable upload actions |
|
|
90
|
+
| `viewType` | `'card'` | View format |
|
|
91
|
+
| `options` | `UploadOptions` | Visual and functional configurations |
|
|
92
|
+
| `accept` | `string` | Allowed file types (e.g., `.jpg,.png`) |
|
|
93
|
+
| `label` | `string` | Upload label |
|
|
94
|
+
| `data` | `any[]` | Existing file data to render |
|
|
95
|
+
| `dialogConfig`| `DialogConfig` | Custom confirmation dialog settings |
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## π€ Example Usage
|
|
100
|
+
|
|
101
|
+
### HTML
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<tis-image-and-file-upload-and-view
|
|
105
|
+
[urlConfig]="urlConfig"
|
|
106
|
+
[entityType]="'announcement_details'"
|
|
107
|
+
[disabled]="false"
|
|
108
|
+
viewType="card"
|
|
109
|
+
[options]="{
|
|
110
|
+
selectorId: 'choosing-image-for-announcement-details',
|
|
111
|
+
height: '108px',
|
|
112
|
+
isStoredDb: false,
|
|
113
|
+
isMultiple: true,
|
|
114
|
+
cols: 5,
|
|
115
|
+
isCompressed: false
|
|
116
|
+
}"
|
|
117
|
+
accept=".png,.jpeg,.jpg"
|
|
118
|
+
label="Upload Image"
|
|
119
|
+
[data]="files"
|
|
120
|
+
[dialogConfig]="getImagePickerDialogConfig()">
|
|
121
|
+
</tis-image-and-file-upload-and-view>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Component (TS)
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
urlConfig: UrlConfig = {
|
|
128
|
+
getUploadUrl: 'https://your-api/get-upload-url',
|
|
129
|
+
attachToEntity: 'https://your-api/attach-to-entity',
|
|
130
|
+
removeImage: 'https://your-api/remove-url',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
files = [
|
|
134
|
+
{
|
|
135
|
+
s3Url: 'https://bucket-url/file1.jpg',
|
|
136
|
+
uploadData: {
|
|
137
|
+
uploadURL: 'https://bucket-url/upload',
|
|
138
|
+
fileName: 'example.jpg',
|
|
139
|
+
uploadPath: '/entity/example.jpg',
|
|
140
|
+
resourceUrl: 'https://bucket-url/example.jpg'
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
getImagePickerDialogConfig(): DialogConfig {
|
|
146
|
+
return {
|
|
147
|
+
title: 'Delete Image',
|
|
148
|
+
message: 'Are you sure you want to delete this image?',
|
|
149
|
+
iconClass: 'tis-text-danger',
|
|
150
|
+
icon: 'delete',
|
|
151
|
+
approveButtonText: 'Yes',
|
|
152
|
+
approveButtonClass: 'tis-btn-danger',
|
|
153
|
+
cancelButtonText: 'No',
|
|
154
|
+
cancelButtonClass: 'tis-btn-primary'
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## πΌοΈ File Types Supported
|
|
162
|
+
|
|
163
|
+
Component auto-detects and handles:
|
|
164
|
+
|
|
165
|
+
- π PDF
|
|
166
|
+
- π· Images (`jpg`, `jpeg`, `png`)
|
|
167
|
+
- πΉ Videos
|
|
168
|
+
- π Excel & CSV
|
|
169
|
+
- π¦ Raw files (opens via download or fallback preview)
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## π Standalone App Integration
|
|
174
|
+
|
|
175
|
+
In `main.ts`:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { provideHttpClient } from '@angular/common/http';
|
|
179
|
+
|
|
180
|
+
bootstrapApplication(AppComponent, {
|
|
181
|
+
providers: [
|
|
182
|
+
provideHttpClient()
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## π¨ Styling
|
|
190
|
+
|
|
191
|
+
The component uses Angular Material β ensure a theme is included:
|
|
192
|
+
|
|
193
|
+
```scss
|
|
194
|
+
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
## π‘ API Contract for Upload Integration
|
|
202
|
+
|
|
203
|
+
The component requires a pre-signed URL from your backend to upload files directly to cloud storage (like AWS S3). You must implement an API endpoint that responds with the following JSON structure:
|
|
204
|
+
|
|
205
|
+
### β
Sample Response from `getUploadUrl`
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"data": {
|
|
210
|
+
"uploadUrlData": {
|
|
211
|
+
"uploadURL": "https://your-s3-bucket/your-object-key.jpg?...",
|
|
212
|
+
"fileName": "your-object-key.jpg",
|
|
213
|
+
"uploadPath": "/folder/your-object-key.jpg",
|
|
214
|
+
"resourceUrl": "https://your-s3-bucket/your-object-key.jpg"
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"message": "Upload Url generated successfully!"
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
- **uploadURL**: This is the pre-signed `PUT` URL. The component will upload the file directly to this URL.
|
|
222
|
+
- **fileName**: Name of the file being uploaded.
|
|
223
|
+
- **uploadPath**: Optional path metadata for organizing resources.
|
|
224
|
+
- **resourceUrl**: The final public/accessible URL for accessing the uploaded file.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## π€ How Upload Works Internally
|
|
229
|
+
|
|
230
|
+
When a user selects a file:
|
|
231
|
+
|
|
232
|
+
1. The component calls your `getUploadUrl` API with basic metadata (like file name/type).
|
|
233
|
+
2. Your backend returns a `PUT` pre-signed URL via `uploadURL`.
|
|
234
|
+
3. The component performs a **`PUT` request directly to that URL**, sending the image or file binary.
|
|
235
|
+
4. After success, the `resourceUrl` is used for rendering or viewing.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## π Backend API Example (Node.js)
|
|
240
|
+
|
|
241
|
+
Hereβs a basic AWS S3 backend implementation in Node.js:
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
const AWS = require('aws-sdk');
|
|
245
|
+
const s3 = new AWS.S3();
|
|
246
|
+
|
|
247
|
+
app.post('/api/get-upload-url', (req, res) => {
|
|
248
|
+
const fileName = req.body.fileName;
|
|
249
|
+
const fileType = req.body.fileType;
|
|
250
|
+
const key = `cm_cases/${uuidv4()}.${fileType.split('/')[1]}`;
|
|
251
|
+
|
|
252
|
+
const params = {
|
|
253
|
+
Bucket: 'your-s3-bucket',
|
|
254
|
+
Key: key,
|
|
255
|
+
ContentType: fileType,
|
|
256
|
+
ACL: 'public-read',
|
|
257
|
+
Expires: 900,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const uploadURL = s3.getSignedUrl('putObject', params);
|
|
261
|
+
res.json({
|
|
262
|
+
data: {
|
|
263
|
+
uploadUrlData: {
|
|
264
|
+
uploadURL,
|
|
265
|
+
fileName,
|
|
266
|
+
uploadPath: `/${key}`,
|
|
267
|
+
resourceUrl: `https://your-s3-bucket.s3.amazonaws.com/${key}`
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
message: "Upload Url generated successfully!"
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
## π€ Contributing
|
|
279
|
+
|
|
280
|
+
1. Clone the repo
|
|
281
|
+
2. Run `npm install`
|
|
282
|
+
3. Use the demo app to test (`projects/` directory)
|
|
283
|
+
4. Submit a PR or issue with details
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## π Publishing to npm
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
git tag v1.0.0
|
|
291
|
+
git push origin v1.0.0
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
GitHub Actions will build and publish to npm automatically if configured.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## π¬ Support / Questions
|
|
299
|
+
|
|
300
|
+
For bugs, suggestions, or feature requests, please open an issue on the [GitHub repository](https://github.com/Thai-Informatics-System/tis-image-and-file-upload-and-view).
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
> Made with β€οΈ by [Thai Informatic Systems Co. Ltd](https://tis.co.th/)
|
|
305
|
+
|