Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9317599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:54:59+00:00 2026-06-19T02:54:59+00:00

I am trying to send a file’s content to the client in my request,

  • 0

I am trying to send a file’s content to the client in my request, but the only documentation Express has is it’s download function which requires a physical file; the file I am trying to send comes from S3, so all I have is the filename and content.

How do I go about sending the content of the file and appropriate headers for content type and filename, along with the file’s content?

For example:

files.find({_id: id}, function(e, o) {
  client.getObject({Bucket: config.bucket, Key: o.key}, function(error, data) {
    res.send(data.Body);
  });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:55:00+00:00Added an answer on June 19, 2026 at 2:55 am

    The type of file depends on the file obviously. Have a look at this:

    http://en.wikipedia.org/wiki/Internet_media_type

    If you know what exactly is your file, then assign one of these to response ( not mandatory though ). You should also add the length of the file to response ( if it is possible, i.e. if it is not a stream ). And if you want it to be downloadable as an attachment, then add Content-Disposition header. So all in all you only need to add this:

    var filename = "myfile.txt";
    res.set({
        "Content-Disposition": 'attachment; filename="'+filename+'"',
        "Content-Type": "text/plain",
        "Content-Length": data.Body.length
    });
    

    NOTE: I’m using Express 3.x.

    EDIT: Actually Express is smart enough to count content length for you, so you don’t have to add Content-Length header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send file info from server to client, but can't receive
I'm trying to send a file to the browser to download, and not having
I'm trying to send a file in chunks to an HttpHandler but when I
I am trying to send an email with an attached file to it but
I'm trying to send an image file through a TCP socket in C, but
I am trying to send a file from a client to a server. The
I'm trying to send a file between a client and a server in my
I m trying to send a csv file in post request and want to
I am trying to send a SOAP request from a xml file and send
I'm trying to send a file from a client to a server, so I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.