TypeError: imageStream.pipe is not a function
Opened this issue · 5 comments
I'm encountering an issue while using the GetObjectResponse object from the OCI Object Storage library. When trying to use the .pipe() method on the value property of the GetObjectResponse, I receive the following error:
TypeError: imageStream.pipe is not a function
Expected Behavior:
The .pipe() method should work as expected on the value property, allowing the stream content to be piped to a response object.
Actual Behavior:
Encountering the "TypeError: imageStreamValue.pipe is not a function" error when attempting to use .pipe() on the value property.
#oci-object-storage-service.ts
async getImageAsStream(folderName: string, imageName: string): Promise<GetObjectResponse | null> {
try {
const authenticationProvider = this.createAuthenticationProvider();
const objectStorageClient = new ObjectStorageClient({
authenticationDetailsProvider: authenticationProvider,
});
const objectName = folderName + '/' + imageName;
const getObjectRequest = {
namespaceName: process.env.OCI_NAMESPACE + '',
bucketName: process.env.OCI_BUCKET_NAME + '',
objectName: objectName,
};
const getObjectResponse = await objectStorageClient.getObject(getObjectRequest);
if (getObjectResponse) {
return getObjectResponse;
}
return null;
} catch (error) {
console.error('Error fetching image stream:', error);
return null;
}
}
Below is my controller:-
#image.controller.ts
@get('/image-stream/{folderName}/{imageName}')
async getImageStream(
@param.path.string('folderName') folderName: string,
@param.path.string('imageName') imageName: string,
@inject(RestBindings.Http.RESPONSE) response: Response,
): Promise<any> {
const ociResponse = await this.cloudStorageService.getImageAsStream(folderName, imageName);
if (ociResponse) {
imageStream = ociResponse.value;
response.setHeader('Content-Type', 'image/png');
imageStream.pipe(response);
} else {
response.status(404).send('Image not found');
}
}
}
Hi @shamnad-sherief , what version of the SDK and NodeJS are you using?
Hi @shamnad-sherief , what version of the SDK and NodeJS are you using?
"oci-sdk": "^2.68.0",
node -v >> v18.16.0
Hi,
does your response has value?
const response = await this.objectStorageClient.getObject(getObjectRequest);
i got an empty response.value
@JJDSNT
No problem with response value.
ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
But it is quiet different from the old version.
@shamnad-sherief I have the same issue. Did you find a solution?
Later add. In node 20 getObject
returns a web stream, which needs to be converted to a node stream:
if (response.value instanceof Readable) {
return response.value;
}
return Readable.fromWeb(response.value);