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 7833629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:48:22+00:00 2026-06-02T12:48:22+00:00

My node js code opens a local png file from my server, tmp.png, and

  • 0

My node js code opens a local png file from my server, tmp.png, and then tries to save it amazon S3. I keep running into problems and I suspect it has something to do with the encoding. The only way it work is with base64 encoding (which I don’t want for my photos).

fs = require('fs');
var awssum = require('awssum');
var amazon = awssum.load('amazon/amazon');
var s3Service = awssum.load('amazon/s3');

var s3 = new s3Service('mykey', 'mysecret', 'account', amazon.US_WEST_1);

fs.readFile('./tmp.png', function (err, data){
    if(err){
        console.log("There was an error opening the file");
    } else {
        s3.PutObject({
            BucketName : 'my-bucket',
            ObjectName : 'tmp.png',
            ContentType : 'image/png',
            ContentLength : data.length,
            Body          : data,
        }, function(err, data) {
            if(err){
                console.log("There was an error writing the data to S3:");
                console.log(err);
            } else {
                console.log("Your data has been written to S3:");
                console.log(data);
            }
        });
    }

});

Obviously my-bucket is actually my unique bucket name. The message I get back from amazon is a request timeout:

Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.

  • 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-02T12:48:24+00:00Added an answer on June 2, 2026 at 12:48 pm

    Looks like a found an example in the docs that does what I need it to. The key was to use fs.stat for the file size and fs.createReadStream to read in the file:

    // you must run fs.stat to get the file size for the content-length header (s3 requires this)
    fs.stat(path, function(err, file_info) {
        if (err) {
            inspect(err, 'Error reading file');
            return;
        }
    
        var bodyStream = fs.createReadStream( path );
    
        console.log(file_info.size);
    
        var options = {
            BucketName    : 'my-bucket',
            ObjectName    : 'test.png',
            ContentType   : 'image/png',
            ContentLength : file_info.size,
            Body          : bodyStream
        };
    
        s3.PutObject(options, function(err, data) {
            console.log("\nputting an object to my-bucket - expecting success");
            inspect(err, 'Error');
            inspect(data, 'Data');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following node.js server-side code: var app = require('http').createServer(handler) , io =
On my node.js server I have the following code: //Generate a token var token
I wrote the following code to count the node of an XML file: private
I'm building a node server that needs to execute code that might be unsafe.
jqGrid tree nodes are read from server using json data. Click in node reads
The following code essentially cats a file with select.select(): f = open('node.py') fd =
I have this code: FILE *f = fopen(intPath, r); Node *n; if (f) {
My code doesn't return the node XmlDocument xml = new XmlDocument(); xml.InnerXml = text;
My code is like var shapes1 = [ r.image(node.gif,190, 100, 47, 45)]; var shapes2
Code: soup=BeautifulSoup(f.read()) data=soup.findAll('node',{'id':'memory'}) print data Output [<node id=memory claimed=true class=memory handle=DMI:000E> <description> System Memory

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.