Skip to content

enzolry/scaleway-s3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

scaleway-s3

Read and write objects to scaleway S3 using fetch() getPublicUrl | glacierObject | restoreObject | getObject | createFolder | createBucket

Install

$ npm install scaleway-s3

Usage

var S3 = require('scaleway-s3')
global.fetch = require('node-fetch')

var s3 = new S3({
    accessKey: '<private accessKey>',
    secretKey: '<private secretKey>',
    region: 'fr-par',
    domain: 'scw.cloud'
});

(async function() {
    try {

        let bucket = 'testbucket';
        let key = '/a/test/file.txt';

        let body = 'test file contents';
        let putResponse = await s3.putObject({bucket, key, body})
        console.log(`put status: ${putResponse.status}`)
        console.log(`put response body: '${await putResponse.text()}'`)

        let path = '/?delimiter=/&marker=&prefix=/a/test/';
        let list = await s3.getList({bucket, path});
        console.log(`get status: ${list.status}`)
        console.log(`get response body: '${await list.text()}'`)

        let key = '/a/test/?acl';
        let aclResponse = await s3.getObject({bucket, key});
        console.log(`get status: ${aclResponse.status}`)
        console.log(`get response body: '${await aclResponse.text()}'`)

        let key = '/a/test2/';
        let getResponseFolder = await s3.createFolder({bucket, key});
        console.log(`get status: ${getResponseFolder.status}`)
        console.log(`get response body: '${await getResponseFolder.text()}'`)

        //work for regular Object.(so restore object before!)
        let expiration_time_limit = 86400;
        let PublicUrl = s3.getPublicUrl({bucket, key, expiration_time_limit})
        console.log(`Public Url: ${PublicUrl}`)
        
        let getResponse = await s3.getObject({bucket, key});
        console.log(`get status: ${getResponse.status}`)
        console.log(`get response body: '${await getResponse.text()}'`)

        let putResponse2 = await s3.glacierObject({bucket, key})
        console.log(`put status: ${putResponse2.status}`)
        console.log(`put response body: '${await putResponse2.text()}'`)

        let days = 250;
        let getResponse1 = await s3.restoreObject({bucket, key, days});
        console.log(`get status: ${getResponse1.status}`)
        console.log(`get response body: '${await getResponse1.text()}'`)


        let delResponse = await s3.deleteObject({bucket, key});
        console.log(`del status: ${delResponse.status}`)
        console.log(`del response body: '${await delResponse.text()}'`)

        let region='fr-par';//fr-par nl-ams pl-waw
        let bucketResponse = await s3.createBucket({bucket, region});
        console.log(`del status: ${bucketResponse.status}`)
        console.log(`del response body: '${await bucketResponse.text()}'`)

    }
    catch (ex) {
        console.log(ex)
    }
}());

License

MIT license; see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%