Skip to content

Commit 79c1156

Browse files
author
Danil Rosomakha
committed
Add uploadImageStream method & Fix updateImage method
1 parent be8810a commit 79c1156

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code.store/arcxp-sdk-ts",
3-
"version": "4.44.0",
3+
"version": "4.45.0",
44
"description": "A strongly typed set of ArcXP API's and utilities reduce the amount of work required to develop with ArcXP, starting with reducing the boilerplate code you have to write.",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/api/photo-center/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { AGallery } from '../../types/gallery';
33
import type { AnImage } from '../../types/story';
44
import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api';
55
import type { GetGalleriesParams, GetGalleriesResponse, GetImagesParams, GetImagesResponse } from './types';
6+
import { ReadStream } from 'node:fs';
67

78
export class ArcProtoCenter extends ArcAbstractAPI {
89
constructor(options: ArcAPIOptions) {
@@ -23,6 +24,19 @@ export class ArcProtoCenter extends ArcAbstractAPI {
2324
return data;
2425
}
2526

27+
async uploadImageStream(readableStream: ReadStream){
28+
const form = new FormData();
29+
30+
form.append('file', readableStream, {
31+
filename: 'file',
32+
contentType: 'application/json',
33+
});
34+
35+
const { data } = await this.client.post('/v2/photos', form, { headers: form.getHeaders() });
36+
37+
return data;
38+
}
39+
2640
async deleteImage(imageId: string) {
2741
const { data } = await this.client.delete(`/v2/photos/${imageId}`);
2842
return data;
@@ -49,7 +63,7 @@ export class ArcProtoCenter extends ArcAbstractAPI {
4963
}
5064

5165
async updateImage(imageId: string, photoDto: AnImage) {
52-
const { data } = await this.client.put<AnImage>(`/v2/photos/${imageId}`, { data: photoDto });
66+
const { data } = await this.client.put<AnImage>(`/v2/photos/${imageId}`, photoDto);
5367
return data;
5468
}
5569
}

0 commit comments

Comments
 (0)