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

Sending raw data is impossible. #57

Closed
reflog opened this issue Dec 27, 2016 · 5 comments
Closed

Sending raw data is impossible. #57

reflog opened this issue Dec 27, 2016 · 5 comments
Labels
type: fix Issues describing a broken feature.

Comments

@reflog
Copy link

reflog commented Dec 27, 2016

Hi!
Thanks for an awesome project! It make writing services in TS a real pleasure.
One bug I came across - even for actions that are marked with a different @ContentType and not inside @jsoncontroller - the result cannot be binary, for example, I cannot send image file.
The reason for it is the following code in ExpressDriver:

 } else {
                    response.send(String(result));
                }

Basically, even if a Buffer is returned - it's converted to string. It's not a correct behavior. At least some sort of escape hatch is needed.

What would you recommend?

@awaragi
Copy link

awaragi commented Jan 8, 2017

I had to return images. Easiest thing is use @res() to inject response object and write directly through it

@reflog
Copy link
Author

reflog commented Jan 9, 2017

@awaragi - do you have a code snippet to demonstrate, maybe? because when I injected @res and tried to set content type I got an error of 'cannot change headers after they are sent'.

@awaragi
Copy link

awaragi commented Jan 10, 2017

@Get(":I'd") get(@Param("id") id: string, @Res() response: any) {
    return this.documentDAO.get(id).then((data) => {
        if (data) {
            response.append("Content-Type", data.mimeType);
            response.end(data.file.buffer, 'UTF-8');
        } else {
            response.status(404);
            // 404 handler will take care of message content
        }
    }).catch((error) => {
        response.status(500);
        return Status.failure(error.message);
    })
}

@pleerock pleerock added the type: fix Issues describing a broken feature. label Apr 3, 2017
@pleerock pleerock mentioned this issue Apr 24, 2017
@pleerock
Copy link
Contributor

this should be fixed in 0.7.0

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: fix Issues describing a broken feature.
Development

No branches or pull requests

3 participants