Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: imageStream.pipe is not a function #223

Open
shamnad-sherief opened this issue Aug 20, 2023 · 5 comments
Open

TypeError: imageStream.pipe is not a function #223

shamnad-sherief opened this issue Aug 20, 2023 · 5 comments

Comments

@shamnad-sherief
Copy link

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');
    }
  }
}
@KartikShrikantHegde
Copy link

Hi @shamnad-sherief , what version of the SDK and NodeJS are you using?

@shamnad-sherief
Copy link
Author

Hi @shamnad-sherief , what version of the SDK and NodeJS are you using?

 "oci-sdk": "^2.68.0",
 node -v  >>   v18.16.0

@JJDSNT
Copy link

JJDSNT commented Oct 9, 2023

Hi,
does your response has value?
const response = await this.objectStorageClient.getObject(getObjectRequest);
i got an empty response.value

@shamnad-sherief
Copy link
Author

@JJDSNT
No problem with response value.

ReadableStream { locked: false, state: 'readable', supportsBYOB: false }

But it is quiet different from the old version.

@greg-md
Copy link

greg-md commented Mar 5, 2024

@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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants