📜 ⬆️ ⬇️

Cloud storage

With the rise of social applications such as Facebook, Instagram, YouTube and many others, managing user-generated content has become a problem, and problems need to be solved. Amazon AWS S3, Google Storage, Rackspace Cloud Files, and other similar services began to appear like mushrooms after the rain to help application developers solve an actual problem — managing a scalable asset repository. And of course they all use the “Cloud”!

Problem


Popular social applications, scientific applications and applications generating media content are capable of generating a huge amount of information in a short period of time. Here are a couple of examples:


When your application starts saving a huge amount of content that your users have generated, your team will have to decide where to invest their time to solve this problem. If your application is designed to place assets on your hardware / infrastructure, your team will spend a lot of time and money trying to efficiently store and manage assets. Alternatively, you can save assets with the cloud storage provider. By choosing this path, you can allow application content to scale almost unlimitedly, paying only for the space and resources used to serve this content. As a result, cloud storage will untie the hands of your engineers and allow you to concentrate on creating unique applications, instead of inventing a bicycle, when scalability becomes a problem.

')

When should you think about using cloud storage for your application?




Integration and access

Most of the leading cloud storage provides access through its API, allowing developers to integrate cloud storage of assets into their application. Below we take a look at a few code examples using the SDK or library for storing assets on Amazon S3.

Ruby & Carrierwave

Code samples are adapted from the CarrierWave repository.

Here are examples of using CarrierWave for uploading to Amazon S3, Rackspace Cloud Files and Google Storage , as well as a few jams for ORM, such as DataMapper , Mongoid and Sequel .

PHP & AWS SDK

Amazon provides PHP SDK for working with AWS APIs and services. For this example, we will use the instructions from the README repository SDK.

Node & Knox

For Node.js, I adapted sample code from a Knox Amazon S3 client on Github.

 //   var client = knox.createClient({ key: '<api-key-here>' , secret: '<secret-here>' , bucket: 'BUCKET-NAME' }); //    S3 client.putFile('some/path-to-file.ext', 'bucket/file-name.ext', function(err, res){ // Logic }); //    S3 client.get('/some/path-to-file.ext').on('response', function(res){ console.log(res.statusCode); console.log(res.headers); res.setEncoding('utf8'); res.on('data', function(chunk){ console.log(chunk); }); }).end(); //    S3 client.del('/some/path-to-file.ext').on('response', function(res){ console.log(res.statusCode); console.log(res.headers); }).end(); 

Conclusion


As you can see, working with AWS S3 APIs is extremely simple and there are a bunch of available libraries for most languages. I would recommend to look at cloud storage when developing your future project. You will save yourself time by not inventing new asset allocation solutions and you will be given an almost unlimited opportunity to scale cloud storage.

Source: https://habr.com/ru/post/173939/


All Articles