Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

uploading json data to s3 bucket in node js

var AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' });
var s3 = new AWS.S3();

var obj = {
    firstname: "Navjot",
    lastname: "Dhanawat"
};

var buf = Buffer.from(JSON.stringify(obj));

var data = {
    Bucket: 'bucket-name',
    Key: 'filename.json',
    Body: buf,
    ContentEncoding: 'base64',
    ContentType: 'application/json',
    ACL: 'public-read'
};

s3.upload(data, function (err, data) {
    if (err) {
        console.log(err);
        console.log('Error uploading data: ', data);
    } else {
        console.log('succesfully uploaded!!!');
    }
});

// IMPORTANT !!!!

// real node js route for POST request
// S3 Upload Test Starts
// const express = require('express');
var AWS = require('aws-sdk');
// for s3 data from create-project
var data;
var buf;
var s3

AWS.config.update({
    accessKeyId: "",
    secretAccessKey: "",
    region: ''
});
s3 = new AWS.S3();

// Define POST route
router.post('/test-upload', (request, response) => {
    buf = Buffer.from(JSON.stringify(request.body)); 
    data = {
        ACL: 'public-read',
        Bucket: "",
        Key: `something/${Date.now().toString()}`,
        Body: buf,
        ContentEncoding: 'base64',
        ContentType: 'application/json',
    };
    s3.upload(data, function (err, data) {
        if (err) {
            console.log(err);
            console.log('Error uploading data: ', data);
        } else {
            console.log('succesfully uploaded!!!');
            response.json({"upload":"successful"});
        }
    });
    
});




// S3 Upload Test Ends
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to change a sting into js code 
Javascript :: can you get reinfected with the coronavirus 
Javascript :: angular multiple validator pattern single input 
Javascript :: nextjs use dotnenv 
Javascript :: esx global error 
Javascript :: bounce of two circles javascript 
Javascript :: function l(){return window.performance 
Javascript :: flutter loops vs javascript loops 
Javascript :: jstree get_json 
Javascript :: negative indexing in arrays javascript 
Python :: python request remove warning 
Python :: get python version jupyter 
Python :: get random line from file python 
Python :: selenium Keys enter python 
Python :: how to shutdown a computer with python 
Python :: python exception with line number 
Python :: python datetime tomorrow date 
Python :: python spawn shell 
Python :: blink raspberry pico 
Python :: install spotipy 
Python :: python mkdir 
Python :: how to check sklearn version in cmd 
Python :: python iterate directory 
Python :: python how to count the lines in a file 
Python :: minimal flask application import 
Python :: change specific column name pandas 
Python :: extended euclidean python 
Python :: save plot as pdf python 
Python :: how to make a tkinter window 
Python :: how to find python location in cmd 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =