polfan-server-js-client 0.2.38 → 0.2.40

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.
@@ -10,7 +10,7 @@ export interface File {
10
10
  }
11
11
  export declare class FilesClient extends AbstractRestClient {
12
12
  protected defaultUrl: string;
13
- uploadFile(file: Parameters<typeof FormData.prototype.append>[1]): Promise<RestClientResponse<File>>;
13
+ uploadFile(file: globalThis.File | Blob): Promise<RestClientResponse<File>>;
14
14
  getFileMeta(id: string): Promise<RestClientResponse<File>>;
15
15
  getFileMetaBulk(ids: string[]): Promise<RestClientResponse<File[]>>;
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.38",
3
+ "version": "0.2.40",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
@@ -13,13 +13,20 @@ export interface File {
13
13
  export class FilesClient extends AbstractRestClient {
14
14
  protected defaultUrl: string = 'https://files.devana.pl';
15
15
 
16
- public async uploadFile(file: Parameters<typeof FormData.prototype.append>[1]): Promise<RestClientResponse<File>> {
17
- const formData = new FormData();
18
- formData.append('file', file);
19
-
20
- let headers = {...this.getAuthHeaders(), Accept: 'application/json'};
21
-
22
- const response = await fetch(this.getUrl('files'), {method: 'POST', body: formData, headers});
16
+ public async uploadFile(file: globalThis.File | Blob): Promise<RestClientResponse<File>> {
17
+ const name = encodeURIComponent((file as globalThis.File).name ?? '');
18
+ let headers = {
19
+ ...this.getAuthHeaders(),
20
+ Accept: 'application/json',
21
+ 'Content-Disposition': `attachment; filename="${name}"`,
22
+ 'Content-Length': file.size
23
+ };
24
+
25
+ const response = await fetch(this.getUrl('files'), {
26
+ method: 'POST',
27
+ body: file,
28
+ headers
29
+ });
23
30
 
24
31
  return this.convertFetchResponse<File>(response);
25
32
  }